Gettting data from textfile

Hi,
I have this data:
seq1 = [1,3,2,3,2,3,1,3];
seq2 = [3,3];
seq3 = [1,2,2,2,2,2,2,2];
seq4 = [1,2,1,1,2,2,1,2,2,1,2];
seqs = {seq1, seq2, seq3, seq4};
How can I get the same data (seq1, seq2, seq3, seq4) from a text file and put them in seqs please?

4 Kommentare

Azzi Abdelmalek
Azzi Abdelmalek am 8 Feb. 2013
post a sample of your text file
Emmanuel
Emmanuel am 8 Feb. 2013
[1,3,2,3,2,3,1,3] [3,3] [1,2,2,2,2,2,2,2] [1,2,1,1,2,2,1,2,2,1,2]
I dont want to include [ and , since they are count as characters. just need to extract numbers only
Azzi Abdelmalek
Azzi Abdelmalek am 8 Feb. 2013
Have you many lines like this?
Emmanuel
Emmanuel am 8 Feb. 2013
[1,3,2,3,2,3,1,3]
[3,3]
[1,2,2,2,2,2,2,2]
[1,2,1,1,2,2,1,2,2,1,2]
For now I have 4.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 8 Feb. 2013
Bearbeitet: Azzi Abdelmalek am 8 Feb. 2013

1 Stimme

clear res
fid = fopen('yourfile.txt');
line1 = fgetl(fid);
res{1}=line1;
while ischar(line1)
line1 = fgetl(fid);
res{end+1} =line1
end
fclose(fid);
res(end)=[];
seqs=cellfun(@str2num,res,'un',0)

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by