Effacer les filtres
Effacer les filtres

How can I read a text file into a list?

16 vues (au cours des 30 derniers jours)
Gabriel Gregory
Gabriel Gregory le 6 Nov 2015
I have a text file containing strings in each row, e.g.
ABC
DEF
PQR
I would like to end up with an object that i can index - i.e. x(1) = 'ABC', x(2) = 'DEF', x(3) = 'PQR'.

Réponse acceptée

Robert Snoeberger
Robert Snoeberger le 6 Nov 2015
You can read into a cell array:
>> data = fileread('file_name');
>> x = strsplit(data);
>> x{1}
ans =
ABC
>> x{2}
ans =
DEF
>>
  1 commentaire
Gabriel Gregory
Gabriel Gregory le 6 Nov 2015
Perfection! Thank you so much.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by