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

readcell()によってテキストファイルをarray化するとき、"," (コンマ)ではなく" "(スペース)で区切りたいのですがどうすればよいでしょうか

Answers (1)

Kojiro Saito
Kojiro Saito on 23 Jun 2022

0 votes

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

Products

Tags

Asked:

on 22 Jun 2022

Answered:

on 23 Jun 2022

Community Treasure Hunt

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

Start Hunting!