.csv file row and line
Show older comments
Hi everyone;
I am using Ubuntu 18.04 and Matlab R2018a.
I have a .csv file with 50000 lines and 3 columns.
a b c
1.12 2.22 3.56
3.07 3.89 3.89
4.98 4.27 4.02
5.44 0.55 1.56
2.66 0.78 1.78
.
.
.
I need to pull values from my file as follows, how can I do it?
[a, b, c] = xlsread('/data.csv' , ......)
Accepted Answer
More Answers (1)
% For earlier version of matlab
fid = fopen("test.csv")
If possible, use '.' as decimal point rather than ','.
% 4,15414 8,63652 0,9690033
c = textscan(fid, "%s %s %s")
n = length(c);
m = length(c{1});
x = zeros(m, n);
for i=1:m
for j=1:n
z(i, j) = str2double(strrep(c{j}{i}, ',', '.'));
end
end
z
% For later version of matlab
T = readtable("test.csv", 'DecimalSeparator', ',') % use ',' for decimal point
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!