Question

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
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top