.csv file row and line
4 次查看(过去 30 天)
显示 更早的评论
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' , ......)
采纳的回答
Neeraj Mirji
2022-6-28
I believe that you are trying to extract first 50,000 rows in a,b and c variable.
If data.csv file has a,b and c as column then, following code extracts first 50,000 rows in a,b and c variable from the .csv file.
dataTable = readtable('data.csv');
[a b c] = [dataTable.a dataTable.b dataTable.c];
If data.csv file has no column names then following code can be used.
dataTable = readtable('data.csv');
[a b c] = [dataTable.Var1 dataTable.Var2 dataTable.Var3];
Hope it helps.
0 个评论
更多回答(1 个)
Chunru
2022-6-28
% 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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!