.csv file row and line
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Srtm
le 28 Juin 2022
Réponse apportée : Neeraj Mirji
le 28 Juin 2022
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' , ......)
4 commentaires
Réponse acceptée
Neeraj Mirji
le 28 Juin 2022
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 commentaires
Plus de réponses (1)
Chunru
le 28 Juin 2022
% 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 commentaires
Voir également
Catégories
En savoir plus sur Entering Commands dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!