テキストファイルをス​ペースで区切り、ar​ray化する方法を教​えてください。

10 views (last 30 days)
雄大
雄大 on 22 Jun 2022
Answered: Kojiro Saito on 23 Jun 2022
readcell()によってテキストファイルをarray化するとき、"," (コンマ)ではなく" "(スペース)で区切りたいのですがどうすればよいでしょうか

Answers (1)

Kojiro Saito
Kojiro Saito on 23 Jun 2022
readcellのドキュメントによると、テキスト ファイルの場合はDelimiterのオプションが指定できますので、以下のようにオプションを指定すれば可能です。
t = readcell('mytext.txt', 'Delimiter', ' ');
上記でうまくいかなかったらdetectImportOptionsでオプションを指定することで可能です。
opts = detectImportOptions('mytext.txt');
opts.Delimiter = ' ';
t = readcell('mytext.txt', opts);

Tags

Products

Community Treasure Hunt

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

Start Hunting!