Subscript indices must either be real positive integers or logicals.while reading data from huge file
1 回表示 (過去 30 日間)
古いコメントを表示
Hello!
I have file with this structure
Step 1
0.10190103
0.10145140
0.10097524
0.10050153
0.10003042
9.95795131E-02
9.91610140E-02
Step 2
9.81189385E-02
9.75561813E-02
9.80424136E-02
0.10000000
0.10000000
9.80617628E-02
9.77829769E-02
...
Step N
0.10000000
0.10000000
9.93788019E-02
0.11977901
0.12290157
0.12588248
0.12861508
I need to assemble it in matrix with row:
V1 = [0.10190103
0.10145140
0.10097524
0.10050153
0.10003042
9.95795131E-02
9.91610140E-02]
V2 = [9.81189385E-02
9.75561813E-02
9.80424136E-02
0.10000000
0.10000000
9.80617628E-02
9.77829769E-02]
...
VN = [0.10000000
0.10000000
9.93788019E-02
0.11977901
0.12290157
0.12588248
0.12861508]
I am trying to do it this way:
function Out = readData (In)
C = strsplit (fileread (In));
Out = cell(1,1); AtStepcount = false; CurrIndex = 0;
for I = 1 : length (C)
if strcmp (C{I}, 'Step'); AtStepcount = true; continue; end
if AtStepcount
CurrIndex = str2num(C{I}); Out{CurrIndex} = []; AtStepcount = false; %#ok<*ST2NM>
continue
Out{CurrIndex} = [Out{CurrIndex}; str2num(C{I})];
end
end
end
And calling it:
A = readData('res.txt')
But it crushes with: "Subscript indices must either be real positive integers or logicals" or "Cell contents indices must be greater than 0" pointing to line Out{CurrIndex} = [Out{CurrIndex}; str2num(C{I})];
Tested sample file is in attachments. Cannot figure out how to make it work.. Any help will be appreciated. Thank you in advance!
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!