How can I read a text file into a list?

30 ビュー (過去 30 日間)
Gabriel Gregory
Gabriel Gregory 2015 年 11 月 6 日
コメント済み: Gabriel Gregory 2015 年 11 月 6 日
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'.

採用された回答

Robert Snoeberger
Robert Snoeberger 2015 年 11 月 6 日
You can read into a cell array:
>> data = fileread('file_name');
>> x = strsplit(data);
>> x{1}
ans =
ABC
>> x{2}
ans =
DEF
>>
  1 件のコメント
Gabriel Gregory
Gabriel Gregory 2015 年 11 月 6 日
Perfection! Thank you so much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by