Error in reading a dat file
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
James Tursa
le 3 Juin 2015
Modifié(e) : James Tursa
le 3 Juin 2015
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.
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!