How to import an array separated by space from a text file?
16 ビュー (過去 30 日間)
古いコメントを表示
I want to import/load/read, whatever works, a textfile.txt where the columns are separated by a space as below:
15 125 2,033.000 2,033.500 285 20
20 350 2,032.500 2,034.000 245 29
17 100 2,032.000 2,034.500 650 34
13 280 2,031.500 2,035.000 370 31
I used the command
X=importdata('test.txt','%s');
but it returned one column with all numbers after each other in it.
I wonder if someone could tell me how to obtain one table from a text file (in this particular case an array with 4 lines and 6 columns).
Thank you in advance for your help
Emerson
0 件のコメント
採用された回答
Walter Roberson
2012 年 8 月 25 日
編集済み: Walter Roberson
2012 年 8 月 26 日
The commas are causing you problems. You need to convert the text to not have any commas before any of the built-in routines will be able to convert it to numeric.
If all you care about is getting the data into a cell array, then see http://www.mathworks.co.uk/matlabcentral/answers/45455-how-can-i-read-a-text-file-line-by-line-containing-titles-of-the-research-papers
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Export についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!