|
On 8 Okt, 14:49, "Ida Haggstrom" <ida_haggst...@yahoo.se> wrote:
> Hi!
>
> I'm trying to save a vector in Matlab as a binary file. Here's what I've done:
> I already have a 32bit binary 3D image (128x128x30 pixels) that I open in Matlab using:
>
> A = fread(fopen(filename),inf,'float32');
> size(A) = 491520 1
>
> I then reshape and pick out only a smaller volume of the image:
>
> B = reshape(A,[128 128 30]); B=B(100:110,100:110,20:30);
> size(B) = 11 11 11
> B=B(:);
> size(B) = 1331 1
>
> I now want to save this new, smaller image (actually vector, B) in the same binary format as the original "filename" format. That is, I want to save the file in "filename2", and be able to open it again in the same way as I opened "filename":
>
> C = fread(fopen(filename2),inf,'float32');
> size(C) = 1331 1
>
> I've tried saving it as a mat-file, but when I open it again (fopen and fread) I get a much shorter vector, so obviously something is lost. Any other suggestions? Thanks a lot!
> Ida
I assume you want to know what statements save the
data to that binary format? If so, something like
fout=fopen(filename2,'wb');
fwrite(fout,B,'float32');
fclose(fout);
should get you close.
Rune
|