Is it possible to fprintf a string to commandline which includes latex characters (I know its possible on figures etc).
The below snippet doesn't work but maybe there's a clever workaround?
a = 45; fprintf(['\lambda=',num2str(a)])
Daniel below mentions a possible HTML to LaTeX workaround - does anyone have a solution in this vain?

댓글 수: 1

Hi, sorry i'm a kinda late :). However i was looking for an answer to the same question and (since Matlab supports HTML code) i tried typing the following lines:
charlambda=char(955); %HTML numeric entity for lambda
a=45;
lambda_string=[num2str(charlambda),' = ', num2str(a),'\n'];sprintf(lambda_string)

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

 채택된 답변

Mark Whirdy
Mark Whirdy 2013년 7월 26일

3 개 추천

Mathworks support:
Thank you for contacting Mathworks.
The feature of typing Greek letter from MATLAB command line is not available in the current releases of MATLAB, this is because that MATLAB is using windows-1252 as its Default Character Set, and from the link below you will see the Greek letters are not included in this Character Set.
<https://en.wikipedia.org/wiki/Windows-1252>
For more reading about this topic, you can refer to the link below:

추가 답변 (1개)

Daniel Shub
Daniel Shub 2013년 7월 25일

1 개 추천

Yes and no. The commandline does not have a LaTeX interpreter so so you cannot pass it LaTeX code. The commandline does handle HTML so if you can go from LaTeX to HTML you can get there. For your case the workaround is simplier:
a = 45; fprintf(['λ=',num2str(a), '\n'])

댓글 수: 9

Thanks Daniel,
It seems that commandline doesn't recognise the greek symbol in your example. I guess because its not an ANSI char set?
>> fprintf(['λ=',num2str(a), '\n'])
=45
>> char(1:200)
ans =
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨&copy;ª«¬­&reg;¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ
Daniel Shub
Daniel Shub 2013년 7월 25일
200 isn't far enough. What does char(955) give you? My MATLAB can display λ just fine.
Mark Whirdy
Mark Whirdy 2013년 7월 25일
편집: Mark Whirdy 2013년 7월 25일
Thats strange.
>> char(955) is a square character . Same for my colleague.
char(955:2000) are all square characters
Jan
Jan 2013년 7월 25일
I get different results with Matlab 6.5, 2009a and 2011b under different operating systems.
Mark Whirdy
Mark Whirdy 2013년 7월 26일
I'm on 2012b Windows XP Version 5.1 (Build 2600: Service Pack 3). I guess I'll ask mathworks support.
Daniel Shub
Daniel Shub 2013년 7월 26일
@Jan what do you get with 6.5? What about with 2009a? 2011b? What OS are these versions running on?
On my Linux system with 2013a char(955) gives me λ.
Jan
Jan 2013년 7월 26일
@Daniel: 2009a/Win7/64: char(955) draws the rectangular shape for an undefined character. This happens for different fonts also. The same happens for 2011b. For 6.5/XP/32 I get a kind of two closing parenthesis. For characters higher than 255, only the lower byte is considered.
Mehmet Mahmudoglu
Mehmet Mahmudoglu 2016년 11월 24일
편집: Mehmet Mahmudoglu 2016년 11월 24일
This code only works for command line but not from m file if you use it in m file you have to use
a = 45; fprintf([num2str(char(955)),' = ',num2str(a), '\n'])
Anurag Gupta
Anurag Gupta 2017년 11월 21일
편집: Anurag Gupta 2017년 11월 21일
why not from .m file?

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

카테고리

도움말 센터File Exchange에서 Labels and Annotations에 대해 자세히 알아보기

질문:

2013년 7월 25일

편집:

2017년 11월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by