MATLAB fread produce error! Invalid Size!

41 ビュー (過去 30 日間)
Amir Ziabari
Amir Ziabari 2019 年 3 月 13 日
コメント済み: Amir Ziabari 2019 年 3 月 13 日
I just run the following simple code to write a binary file and then read it in MATLAB.
It produces: Error using fread! Invalid Size!!
Any idea?!
% write a binary file
clear
clc
m=uint16(randi([0 5000],100,150, 50));
f=fopen('xtest','w');
fwrite(f,m,'uint16','ieee-le');
fclose(f);
% read the same binary file!
clear
clc
x0=fopen('xtest');
pj=fread(x0,[100, 150, 50],'uint16','ieee-le');%
fclose(x0);

採用された回答

Geoff Hayes
Geoff Hayes 2019 年 3 月 13 日
Amir - according to fread dimensions of output vector, this vector/array can only be a two-element row vector wheras you are trying to read a three dimensional array. You probably need to read in the data as
pj=fread(x0,[100, 150*50],'uint16','ieee-le');%
and then use reshape to get the correctly size array
pj = reshape(pj, [100 150 50]);
I tried this for a smaller three dimensional array and it seemed to work fine.
  1 件のコメント
Amir Ziabari
Amir Ziabari 2019 年 3 月 13 日
Great! Thanks.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by