|
Hello, i´m new to matlab and have a question about a function i´ve been writing.
What i need to do is read 10 files named regiao(1-10).txt, this is the code i have so far:
function l=ler(nome)
regiao=dir('regiao*.txt');
for k=1:10;
nome=regiao(k).name;
id=fopen(nome,"r");
while !feof(id)
coluna=fgets(id);
populacao=split(coluna,'Populacao:');
if !isempty(populacao);
l(k).populacao=populacao;
for f=1:length(coluna);
[semana,infectados,mortes]=fscanf(id,"%s%s%s","C");
if !isempty(semana);
l(f).semana=semana;
l(f).infectados=infectados;
l(f).mortes=mortes;
f=f+1;
endif
endfor
endif
endwhile
endfor
fclose(id);
endfunction
The files i need to read have a structure like this:
Populacao:20000
Semana Infectados Mortes
6 26 26
28 512 192
50 295 100
69 39 20
and i need to retrieve the number in the first line (that part works) and the numbers in the columns (that's the problem), instead of retrieving the information in all the 10 files my function only gets one value form each file.
Can anyone help me?
Thank you for your time.
|