How to read data one by one
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Joe kiao
il 22 Gen 2015
Commentato: Matz Johansson Bergström
il 23 Gen 2015
The file is like
2
0.5 0.6 0.7
0.0 -2.5 6.3
The first line is the number of points. The others are the coordinates of those points x y z.
In C++, we have
ifstream fin("coordinate.txt");
fin>>num;
for(int i=0; i<num; i++)
{
fin>>array[i][0]>>array[i][1]>>array[i][2];
}
What are the corresponding code in MATLAB?
0 Commenti
Risposta accettata
Matz Johansson Bergström
il 23 Gen 2015
It should be sufficient to write
filename='coordinates.txt';
[x,y,z] = dataread('file', filename, '%f%f%f', 'delimiter',...
' ', 'headerlines', 1);
4 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Workspace Variables and MAT-Files in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!