How to read a non uniform text file in Matlab
Afficher commentaires plus anciens
Hello!
I have a non uniform text file which I want to read in MATLAB. The file may be found here:
Can I create a matrix where cells could be left blank while some of them would recognize characters and others numbers?
From this file I wish to keep every second value (first column)
For example from every b group like the one following
b2
5.00 0.00 0.00
5.00 0.00
I only wish to keep the respective 5.0 value in a single column matrix along with all the other respective values from b1, b3, b4, .... , b48.
Thank you so very much!
Giorgos
Réponse acceptée
Plus de réponses (1)
Hi Giorgios, this file should do the job:
fid = fopen('file2.txt');
s = fgets(fid); % get line with a 'b'
i = 1;
while s ~= -1
d = fscanf(fid, '%f\n', 5); % get next 5 numbers
b(i) = d(1); % store first number in b
i = i + 1;
s = fgets(fid);
end
fclose(fid)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!