- Remove the alternate empty lines
Index exceeds the number of array elements (1)
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm confused as to why I'm getting this error:
Index exceeds the number of array elements (1).
Error in ReadVTData2 (line 25)
col2(i) = str2double(str_col(2));
Error in ProcessVT (line 8)
[data, numrows]= ReadVTData2(VTfilename);
It works well for line 24 but not 25. Please explain.
0 commentaires
Réponse acceptée
KSSV
le 15 Oct 2020
Your file nums2.txt has alternate lines of data..every alterate line is a empty line, when you try to read using the file using line:
getrow=fgetl(fileID);
you will get empty str_col
So these lines:
col1(i) = str2double(str_col(1));
col2(i) = str2double(str_col(2));
throwing error.
Two options:
Or, use if else conditon in the file ReadVTData2.m
if length(str_col) > 2
col1(i) = str2double(str_col(1));
col2(i) = str2double(str_col(2));
end
NOTE: There are many other elegant ways of reading such files. You can better use readtable.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Audio and Video Data dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!