MATLAB: Stop exponential answers

exponentialformatnumber

Dear all,
I have two values representing the max and min of a data vector.
max_val = 0.9855;
min_val = 0.9851;
Both are of type 'double'. However, when I try to subtract the min from the max:
diff = max_val - min_val;
the answer 3.6023e-04 is returned instead of 0.0004. How can I ensure that this answer is expressed without the exponentiation?

Best Answer

Hi,
there is no type in format that generally tells MATLAB to use such a format. Nevertheless you can always use sprintf to make a string in the format you like, in this case it would be
sprintf('%f', diff)
ans =
0.000400
Titus