load text file with specific format
Afficher commentaires plus anciens
Hello,
I have a problem loading a text file that has format like this:
20
65
33
500
12 34 3.99
14 20 6.09
12 31 2.90
I have tried different functions e.g(import data,open, load,textscan ... ), none of them works. I need to use the above format as it is.
any suggestions please.
Réponses (1)
Walter Roberson
le 12 Mar 2014
fid = fopen('YourFile.txt', 'r');
first4cell = textscan(fid, '%g', 4);
restcell = textscan(fid, '%g%g%', 'CollectOutput', 1);
fclose(fid);
first4 = first4cell{1};
rest = restcell{1};
now first4 will be a column vector containing the 4 leading values, and rest will be an N x 3 matrix containing the values from the remainder of the file.
3 commentaires
Mr. Unkown
le 12 Mar 2014
Walter Roberson
le 13 Mar 2014
What datatype would you want it stored before you send it? What format does the executable need the data to be in?
Mr. Unkown
le 13 Mar 2014
Catégories
En savoir plus sur Standard File Formats dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!