Ältere Kommentare anzeigen
Hi so im trying to use fread in a very simple program. Ive used the following to write 4 numbers into a .txt file:
fid=fopen('data.txt','wt');
fprintf(fid,'%0.0f %0.0f %0.0f %0.0f', 2, 4, 6, 8);
fclose(fid);
Now i want to read the data back in by reopening the file and reading into an array:
fid=fopen('data.txt');
numbers=fread(fid);
now if i output 'numbers' i get some completely random numbers:
[ 50 32 52 32 54 32 56]
What am i doing wrong? I should be getting [2 4 6 8] back?
Also if anyone knows why im getting an output 'ans=0' that would be useful too.
Thanks!
Akzeptierte Antwort
Weitere Antworten (1)
Sean de Wolski
am 4 Apr. 2012
0 Stimmen
You have to specify the precision of the numbers you're reading (i.e. double).
You could also look at dlmread and dlmwrite if the whole text file will be numbers.
1 Kommentar
Edward
am 4 Apr. 2012
Kategorien
Mehr zu Text Files finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!