Clear Filters
Clear Filters

changing format of number displayed on figure

16 views (last 30 days)
Hi, I have 2 sets of data 'a' and 'b' which I have plotted in a figure. I've then integrated under this curve using 'trapz' and then displaying this result on the figure. This is all successful however I want to change the format of the displayed number to scientific notation instead of a long number. I've used 'format longEng' but this is unsuccessful. (This is all within a for loop).
------
plot(x,y);
xlabel('x data')
ylabel('y data');
legend('Background Corrected');
title(figure_caption);
set(gca, 'YScale', 'log');
format longEng;
integration2 = trapz(x, y);
integration_text2 = 'curve integration =';
integration_info2 = [integration_text2, ' ', num2str(integration2)];
disp(integration_info2);
dim = [0 0.95 0.05 0.05];
annotation('textbox', dim, 'String', integration_info2, 'FitBoxToText', 'on');
end
------
thanks

Accepted Answer

Steven Lord
Steven Lord on 5 Apr 2018
The format function affects only how numeric arrays are displayed in the Command Window. To affect how they are written to a char vector or string that you can use as the String property of a graphics object, use sprintf or specify a precision or format specifier as the second input to the num2str function. See the documentation pages for those functions for examples.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!