How to read comma separated .txt file in matlab R2018a?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
How to read comma separated .txt file in matlab R2018a?
The rows is like this :
And I want only the data which begins in "Sensor1:.#A-R="
Sensor1:.#A-R=-1.00,-20.00,226.00
Sensor2:.#A-R=-13.00,-43.00,297.00
Sensor3:.#A-R=-10.00,-11.00,216.00
Sensor1:.#A-R=-2.00,-18.00,224.00
Sensor2:.#A-R=-15.00,-41.00,298.00
Sensor3:.#A-R=-11.00,-11.00,220.00
Sensor1:.#A-R=-2.00,-17.00,227.00
Sensor2:.#A-R=-15.00,-42.00,298.00
Sensor3:.#A-R=-9.00,-12.00,225.00
Sensor1:.#A-R=-2.00,-18.00,228.00
Sensor2:.#A-R=-15.00,-42.00,297.00
Sensor3:.#A-R=-10.00,-14.00,227.00
Sensor1:.#A-R=-1.00,-21.00,229.00
Sensor2:.#A-R=-14.00,-45.00,297.00
...
...
..
.
.
and so on
I want to store the data which begins in "Sensor1:.#A-R=" in a matrix, (I mean only the number values)
0 commentaires
Réponse acceptée
Walter Roberson
le 26 Fév 2023
S = fileread(FILENAME);
S = regexprep(S, '^#A-R=', '', 'lineanchors');
data = cell2mat( textscan(S, '%f%f%f', 'delimiter', ',') );
3 commentaires
Walter Roberson
le 26 Fév 2023
testdata = {
'Sensor1:.#A-R=-1.00,-20.00,226.00'
'Sensor2:.#A-R=-13.00,-43.00,297.00'
'Sensor3:.#A-R=-10.00,-11.00,216.00'
'Sensor1:.#A-R=-2.00,-18.00,224.00'
'Sensor2:.#A-R=-15.00,-41.00,298.00'
'Sensor3:.#A-R=-11.00,-11.00,220.00'
'Sensor1:.#A-R=-2.00,-17.00,227.00'
'Sensor2:.#A-R=-15.00,-42.00,298.00'
'Sensor3:.#A-R=-9.00,-12.00,225.00'
'Sensor1:.#A-R=-2.00,-18.00,228.00'
'Sensor2:.#A-R=-15.00,-42.00,297.00'
'Sensor3:.#A-R=-10.00,-14.00,227.00'
'Sensor1:.#A-R=-1.00,-21.00,229.00'
'Sensor2:.#A-R=-14.00,-45.00,297.00'};
D1 = tempname() + ".txt";
writelines(testdata, D1);
S = fileread(D1);
S = regexp(S, '(?<=^Sensor1:.#A-R=)[^\n]+$', 'match', 'lineanchors');
S = strjoin(S, '\n');
data = cell2mat( textscan(S, '%f%f%f', 'delimiter', ',') );
data
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Export 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!