Gettting data from textfile

2 ビュー (過去 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 Center および File ExchangeText Data Preparation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by