Reputation: 2604
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
Upvotes: 0
Views: 553
Reputation: 36720
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.
Upvotes: 2