I have a CSV like this (one line):
101, 120, 130
How can I scan these into variables like this:
pt_num = 101
x = 120
y = 13
Just use csvread:
M = csvread('filename.csv');
pt_num = M(:,1);
x = M(:,2);
y = M(:,3);
You can also use textscan
to get each column in a cell array:
fid = fopen('filename.csv','r');
C = textscan(fid,'%d, %n, %n');
fclose(fid);
And there is fscanf
, but you will have to reshape the array:
fid = fopen('filename.csv','r');
M = fscanf(fid,'%d, %f, %f')
fclose(fid);
M = reshape(M,3,[])';
Finally, dlmread
, which works just like csvread
:
M = dlmread('filename.csv',',');