How to get a csv file excluding first row and last column to run through if statement?
Mostra commenti meno recenti
I'm new to matlab so I hope this makes sense!
The first row is headings and the last column is not needed for the if statement. I need the file to run through the ifelse statement without defining the number of rows so that numerous different files can run through it at different times with me just changing the file name.
I have been using the following code:
fid = fopen('test.csv');
data = textscan(fid,'%f %f %f %f %f %f %f %f %f %f %f %f %f %*s','Delimiter',',','Headerlines',1);
fclose(fid);
numrows = size(fid,1);
for rownum = 1:numrows;
thisrow = fid(rownum,:);
val1 = thisrow(1);
val2 = thisrow(2);
val3 = thisrow(3);
val4 = thisrow(4);
With val1 etc being the column data for the ifelse statement. There are 13 columns (val1...val13).
However the error below keeps appearing:
Index exceeds the number of array elements (1).
Error in test2 (line 8)
val2 = thisrow(2);
Does anyone have advice that can help me?
Thanks
Risposta accettata
Più risposte (2)
Fangjun Jiang
il 13 Nov 2018
Let's fix the biggest issue first. Should be
numrows = size(data,1);
thisrow = data(rownum,:);
Peggatha
il 13 Nov 2018
0 voti
1 Commento
per isakson
il 13 Nov 2018
Modificato: per isakson
il 13 Nov 2018
My standard answer
* See <https://se.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html Debug a MATLAB Program>
* See <https://se.mathworks.com/help/matlab/matlab_prog/examine-values.html Examine Values While Debugging>
Too bad copy&paste of hyperlinks doesn't work with the new Answer Editor
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!