how to write numbers with 10^ format in matlab?

조회 수: 29 (최근 30일)
MP
MP 2022년 8월 10일
댓글: MP 2022년 8월 11일
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