Domanda

I am processing an image and want to save the result into binary ubit1 file, but I am getting unexpected results.

    >> fid=fopen('test.test','w');
    >> fwrite(fid,'100101','ubit1');
    >> fclose(fid);
    >> fid=fopen('test.test','r');
    >> A=fread(fid,'ubit1');
    A =
         1
         1
         1
         1
         1
         1
         0
         0
È stato utile?

Soluzione

You ware using char input arguments. Using a logical column vector produces the expected results.

fwrite(fid,logical([1 0 0 1 0 1])','ubit1');

The returned vector is [1 0 0 1 0 1 0 0] because the byte must be filled.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top