Thread Subject:
Reading multiple files

Subject: Reading multiple files

From: Sofia

Date: 27 May, 2012 16:03:09

Message: 1 of 1

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.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us