0

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
asakryukin
  • 2,524
  • 1
  • 13
  • 14

1 Answers1

2

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.

Daniel
  • 36,610
  • 3
  • 36
  • 69