How to open .dat file

57 ビュー (過去 30 日間)
mohd akmal masud
mohd akmal masud 2024 年 11 月 5 日 2:41
移動済み: Walter Roberson 2024 年 11 月 8 日 4:47
Dear All,
I have .dat file as attached. I tried open using this script but an error.
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate
size for that dimension.
unzip xcat_wb.zip
fid = fopen('xcat_wb.dat','rb');
arr = fread(fid,'int8');
fclose(fid);
dim = [364,364,110];
arr = reshape(arr,dim)
volshow

採用された回答

Sameer
Sameer 2024 年 11 月 5 日 2:56
The error occured because the total number of elements is not equal to 364 * 364 * 110
unzip('xcat_wb.zip');
fid = fopen('xcat_wb.dat', 'rb');
arr = fread(fid, 'int8');
fclose(fid);
numElements = numel(arr)
numElements = 131235840
disp(364 * 364 * 110);
14574560
  2 件のコメント
mohd akmal masud
mohd akmal masud 2024 年 11 月 5 日 3:30
So how?
Walter Roberson
Walter Roberson 2024 年 11 月 5 日 3:58
disp(131235840 / 14574560)
9.0044
So the actual file has a little over 8 bytes for each expected array element. That suggests that array elements are expected to be stored in double precision.
But even so, there would be parts of the file left over from [364, 364, 110] double precision elements. That suggests that either there is a substantial header (over 14 megabytes), or else that the data forms only a small portion of the file.
You need documentation as to the internal storage format of the .dat file. The file extension ".dat" is not standardized; it can refer to any random data format.

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

その他の回答 (1 件)

mohd akmal masud
mohd akmal masud 2024 年 11 月 5 日 7:07
移動済み: Walter Roberson 2024 年 11 月 8 日 4:47
unzip xcat_wb.zip
fid = fopen('xcat_wb.dat','rb');
arr = fread(fid,'int8');
fclose(fid);
dim = [384,384,890];
arr = reshape(arr,dim);
volshow(arr)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by