Read fixed number of numbers from text file

3 vues (au cours des 30 derniers jours)
Brahim Aboumouadine
Brahim Aboumouadine le 5 Jan 2021
i have this matrix bellow save in a text file called test.txt
1 2 3 ...... ......100
101 102 ...... ..200
...........................
901 902 .......1000
i want to read only the first 500 numbers from it . how to do it ?
thanks in advance

Réponse acceptée

Jeremy Hughes
Jeremy Hughes le 5 Jan 2021
Modifié(e) : Jeremy Hughes le 5 Jan 2021
I assume the dots are meant as ellipses and not literally dots in the file. If so, you can use textscan pretty effectively here.
fid = fopen(filename);
d = textscan(fid,'%f',500);
d = d{1};
fclose(fid);
And if there are literally dots,
d = textscan(fid,'%f',500,'Whitespace',' .');
  1 commentaire
Brahim Aboumouadine
Brahim Aboumouadine le 5 Jan 2021
this was really helpful , thanks a lot :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Cell Arrays 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!

Translated by