Displaying exponential notation with num2str?
Show older comments
I have a value that I want to display within a textbox in a figure. The value hoewer needs to be in exponential notation.
Example:
lambda = 2.4321;
vD = 3.2e5;
fighandle = figure(1);
fighandle.Color = [1,1,1];
fighandle.Position = [10,50,600,400];
fighandle.Name = 'Test';
xlabel('t [min]','FontSize',12,'Interpreter','latex');
ylabel('Temperatur [$^\circ$C]','FontSize',12,'Interpreter','latex');
annotation('textbox', [0.66, 0.15, 0.1, 0.1], ...
'String', {['$\lambda$ = ' num2str(round(lambda,3),'%.3f') ' W/mK'], ...
['$v_D$ = ' num2str(round(vD,1),'%.1f') ' m/s']}, ...
'BackgroundColor', 'White', ...
'Interpreter','latex');
The result looks like this:

But i want the variable b to look like this:
Any ideas? Thank you very much for the help!
Accepted Answer
More Answers (1)
Another function that might be of interest to you is formattedDisplayText, if you want to capture how the variable would be displayed in MATLAB using a certain display format.
x = pi
y1 = formattedDisplayText(x)
format longeng
x
y2 = formattedDisplayText(x)
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!