Read Numbers from .dat file in the format of a 3d matrix
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have a .dat file as below:
1, 2, 4, 2, 4
3, 4, 6, 1, 5
...
They are 40 numbers, 8 lines and 5 columns.
Now,
I want to read it by matlab as a 3d matrix: 4*2*5
If you suggest textscan please give me some hints how to use it. Thanks alot!
0 件のコメント
採用された回答
Jan
2013 年 10 月 7 日
There are many different versions to reshape the data to 4x2x5. Perhaps you want:
fid = fopen(FileName, 'r');
if fid == -1, error('Cannot open file for reading.'); end
data = fscanf(fid, '%g,%g,%g,%g,%g', [5, Inf]);
data = reshape(transpose(data), [4,2,5])
fclose(fid);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!