Gettting data from textfile

조회 수: 3 (최근 30일)
Emmanuel
Emmanuel 2013년 2월 8일
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일
Have you many lines like this?
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]
For now I have 4.

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 8일
편집: Azzi Abdelmalek 2013년 2월 8일
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)
  댓글 수: 1
Emmanuel
Emmanuel 2013년 2월 8일
brilliant it works! thanks a lot.

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

추가 답변 (0개)

카테고리

Help CenterFile 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