I have a double array in matlab whose elements are being output to a file in hexidecimal format. I want to output it with no decimal places and I can’t seem to figure out how to do this when the value being output is a negative number. I’ve tried:
>> A = ones(1,4);
>> fid = fopen('test.txt', 'r');
>> value = A(2);
>> fid = fopen('test.txt', 'w');
>> fprintf(fid,'%x\r\n', value);
>> fprintf(fid,'%.0x\r\n', value);
>> value = -value;
>> fprintf(fid,'%.0x\r\n', value);
>> fprintf(fid,'%0.0x\r\n', value);
>> fprintf(fid,'%0.0x\r\n', value);
>> fprintf(fid,'%1.0x\r\n', value);
>> fprintf(fid,'%x\r\n', value);
And the output file looks like:
1
1
-1e+000
-1e+000
-1e+000
-1e+000
-1.000000e+000
I really just want it to be able to print out ‘-1’;
Sorry if this is obvious but its really hard to find this information as there are so many different formats.
Did you try changing
value = -value;tovalue = round(-value);?Alternatively, output absolute values only, but prepend ‘-‘ if the value is negative: