How can I raise a power in gui edit text

조회 수: 32 (최근 30일)
Emre Kaynar
Emre Kaynar 2018년 12월 18일
댓글: Image Analyst 2020년 11월 26일
Hello everyone
As i asked on the title I want to raise a power in edit text. like P1
I tried with latex but it didn't work for me
Thank you

답변 (3개)

Rik
Rik 2018년 12월 18일
편집: Rik 2018년 12월 18일
There is not a lot of support for rich text formatting in Matlab. I don't really know any editable field where you can use it.
In several static text places you can use rich text formatting (e.g. by using the LaTeX interpreter for text, title, etc), but outside of those I don't know of a method that would allow this.
A possible loophole is with the special unicode characters:
%superscript 0123456789
char([8304 185 178 179 8308 8309 8310 8311 8312 8313])
(note that char values beyond 255 can have a limited support depending on release and OS)
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 12월 18일
The unicode characters Rik mentions are the only way to do it with uicontrol style edit, unless you are willing to go in at the Java level.
In particular tex and latex are not supported for uicontrol style edit. Also HTML character entities and CSS are not supported for uicontrol style edit. HTML character entities are supported for some of the other uicontrol styles.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2018년 12월 18일
Is this what you're looking for?
% Put P1 squared with subscript 5
title('P1^2_5', 'Interpreter', 'tex', 'FontSize', 20);
0001 Screenshot.png
  댓글 수: 4
Walter Roberson
Walter Roberson 2020년 11월 26일
If you use a text area then you could risk using num2str() . Or you could do text processing:
S = '3.33 *10^-12'
S = '3.33 *10^-12'
num = str2double(regexprep(S, '\s*\*\s*10\^(-?\d+)', 'E$1'))
num = 3.3300e-12
Image Analyst
Image Analyst 2020년 11월 26일
It can be difficult trying to parse user input. For example did they use spaces, etc.? Did they use an exponent? Etc. Here's a start:
S = '3.33 *10^-12'
% S = '3.34' % See if it works with no exponent
% Remove any spaces.
S = strrep(S, ' ', '')
index1 = strfind(S, '*10^') - 1;
% Find the first number
if isempty(index1)
n1 = str2double(S) % No exponent, just take the whole number.
else
n1 = str2double(S(1:index1))
end
% Find the exponent - the second number.
index2 = strfind(S, '^') + 1;
if ~isempty(index2)
n2 = int32(str2double(S(index2:end)))
caption = sprintf('%.2f * 10^{%d}', n1, n2)
else
% No *10 to a power, it's just a number.
caption = sprintf('%.2f', n1)
end
title(caption, 'Interpreter', 'tex', 'FontSize', 20);

댓글을 달려면 로그인하십시오.


Cris LaPierre
Cris LaPierre 2018년 12월 19일
편집: Cris LaPierre 2018년 12월 19일
Here's a post of all the available text edit options in app designer. In summary, it is possible to use an interpreter in axis titles, text objects in an axis, colorbar label strings, and legend titles.
All other components do not yet support interpreters (as of 2018a).

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by