Subscript indices must either be real positive integers or logicals.while reading data from huge file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!