I am trying to read a CSV file in matlab. I just want to read the second column but the code below prints out everything on CSV file. What parameters or functions I have to introduce to make it read just the second column
FILENAME = 'C:\Users\Desktop\Results.csv';
fid = fopen(FILENAME, 'rt');
a = textscan(fid, '%s', 'HeaderLines',1,'Delimiter',',');
fclose(fid);
celldisp(a)
There are several ways:
Using cvsread
:
Assuming you have N
rows in the file1:
a = csvread( FILENAME, 0, 1, [0 1 N-1 1 ] );
You might also consider xlsread
a = xlsread( FILENAME, 'B:B' );
See specific example on the xlsread
doc.
Another option is dlmread
a = dlmread( FILENAME, ',', [0 1 N-1 1] );
1 - A nice (and fast) way to count the number of lines in the file in Matlab can be found in this answer by Rody Oldenhuis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With