how to write numbers with 10^ format in matlab?

34 次查看(过去 30 天)
How to print 123456 as 1.2x10^5 in a matlab figure?
str5 = ['CC = ' num2str(123456) ];
str = sprintf('%s',str5);
annotation('textbox',[0.1 0.1 0.1 0.1],'String',str,'FitBoxToText','on');
Any help will be greatly appriciated.

采纳的回答

Stephen23
Stephen23 2022-8-10
编辑:Stephen23 2022-8-10
str = strrep(sprintf('CC = %.1e',123456),'e','x10^')
str = 'CC = 1.2x10^+05'
str = regexprep(sprintf('CC = %.1e',123456),'e(\D)0*(\d+)$','x10^$1$2')
str = 'CC = 1.2x10^+5'
  4 个评论
Stephen23
Stephen23 2022-8-10
编辑:Stephen23 2022-8-10
"Why does that appear like this"
This is due to how the graphics engine interprets text. You need to either:
str = strrep(sprintf('CC = %.1e',123456),'e','x10^')
str = 'CC = 1.2x10^+05'
plot(0:1,0:1)
annotation('textbox',[0.5,0.5,0.1,0.1],'String',str,'interpreter','none')
MP
MP 2022-8-11
str = strrep(sprintf('CC = %.1e',123456),'e','x10\^');
worked!!
Thank you so much @Stephen23

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by