fwrite to fread changes data completely!
Afficher commentaires plus anciens
Hello Friends,
I have a Vector or some length, say, 1 x N with real number entries.
I want to save this vector by using "fwrite" and then read it using "fread". I did the following:
fileID = fopen(Name, 'w');
fwrite(fileID, Vector, 'double', [number_of_rows number_of_columns]);
%Here [number_of rows number_of_cols] = size(Vector);
fclose(fileID);
In workspace, Vector shows of type 'double'
Next, for reading it, I did the following:
fid = fopen(path_to_vector, 'r');
output = fread(fid, [1 length_of_vector], 'double');
fclose(fid);
However, the "output" shows completely different values than what I saved using "fwrite". I tried to change precision from double to type float, int, etc., but it does not work. How can I get exactly the same vector what I saved?
I will appreciate any advise!
2 commentaires
per isakson
le 9 Juil 2016
Are you writing and reading on the same system?
hello_world
le 9 Juil 2016
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Low-Level File I/O dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!