필터 지우기
필터 지우기

Error in reading a dat file

조회 수: 4 (최근 30일)
Millone
Millone 2015년 6월 3일
편집: James Tursa 2015년 6월 3일
I am trying to read a binary file that was written as following:
if success== true
[row,col,v] = find(A);
row = uint32(row);
col = uint32(col);
fwrite(fid,size(A),'uint32');
fwrite(fid,nnz(A),'uint32');
for i = 1:size(v,1)
fwrite(fid, row(i), 'uint32');
fwrite(fid, col(i), 'uint32');
fwrite(fid, v(i), 'double');
end
end
using:
n = fread(fid,1,'double')
dims = fread(fid,n,'double')
A = fread(fid,'double')
A = reshape(A,dims')
fclose(fid);
but I get an error: Error using reshape Size vector must have at least two elements. Error in sparse(line 10) A = reshape(A,dims')
How can I solve this problem? Any help will be appreciated. Thanks

답변 (1개)

James Tursa
James Tursa 2015년 6월 3일
편집: James Tursa 2015년 6월 3일
How is fread supposed to know that you wrote uint32 values to the file unless you tell it? Read in the uint32 values as uint32, not double.
EDIT:
Maybe something like this (CAVEAT: I am not on a machine with MATLAB at the moment so this is untested)
size_A = fread(fid,[1 2],'uint32');
nnz_A = fread(fid,[1 1],'uint32');
row = zeros(nnz_A,1,'uint32');
col = zeros(nnz_A,1,'uint32');
v = zeros(nnz_A,1);
for i = 1:nnz_A
row(i) = fread(fid, [1 1], '*uint32');
col(i) = fread(fid, [1 1], '*uint32');
v(i) = fread(fid, [1 1], 'double');
end
Then rebuild A from the pieces.
  댓글 수: 1
Millone
Millone 2015년 6월 3일
Thanks for your comment. It is progressing but now, after I changed to uint32 I have a new error. Error using reshape To RESHAPE the number of elements must not change.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by