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

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 8일
post a sample of your text file
Emmanuel
Emmanuel 2013년 2월 8일
[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 2013년 2월 8일
Have you many lines like this?
[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.

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 8일
편집: Azzi Abdelmalek 2013년 2월 8일

1 개 추천

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)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Text Data Preparation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by