Read Numbers from .dat file in the format of a 3d matrix

2 ビュー (過去 30 日間)
Hossein
Hossein 2013 年 10 月 7 日
コメント済み: Hossein 2013 年 10 月 7 日
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!

採用された回答

Jan
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);
  1 件のコメント
Hossein
Hossein 2013 年 10 月 7 日
Thanks alottttttttttttt!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by