Display Interpreted Latex string outside a plot

50 ビュー (過去 30 日間)
Pierre
Pierre 2020 年 7 月 18 日
コメント済み: Bhupendra Kumar 2021 年 10 月 31 日
Hi there,
I want to show in my output (not in my plots) the handwritten format of my expression. I have the symbolic toolbox.
% No problem in plots, simple example
x=linspace(0*deg,360*deg,360); % deg is constant in my installation
f='sqrt(abs(sin(x.^2)))'; ff = eval(f);
p=plot(x,ff);
title(['Title ' '$' latex(str2sym(f)) '$'] , 'Interpreter', 'latex');
Now suppose I don't need a plot of any kind and I want to check if I made a mistake in a long expression or equation.
I'd like to show the hand written format of my expression
Refering to the little code over
If I type ['$' latex(str2sym(f)) '$']
I will get the Latex representation ans = '$\sqrt{\left|\sin\left(x^2\right)\right|}$'
Now I want to do this something like this
disp(['$' latex(str2sym(f)) '$'] , 'Interpreter', 'latex');
and get
Can I do something like this ? Not with disp(...) for sure !
  3 件のコメント
Pierre
Pierre 2020 年 7 月 18 日
編集済み: Pierre 2020 年 7 月 18 日
No.
Assume there is no plot, I cannot use title alone.
I forgot to say that I use the Live Editor and common sense tells me that the output must be a text region
So I rewrite the code, it should be as simple as that with no plot !
clf
x=linspace(0*deg,360*deg,300);
f='sqrt(abs(sin(x.^2)))'; ff = eval(f);
SomeCallingFunctionOrSomething(['$' latex(str2sym(f)) '$'] , 'Interpreter', 'latex');
And it should add or modify a text region with
Of course I can do it manually just take \sqrt{\left|\sin\left(x^2\right)\right|} then Insert LaTex Equation and Paste and it will add my text region with the correct output but I want to do it programmatically.
Bhupendra Kumar
Bhupendra Kumar 2021 年 10 月 31 日
Wait for this thing to happen.

サインインしてコメントする。

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 18 日
sympref('TypesetOutput','default')
f = str2sym('sqrt(abs(sin(x.^2)))') % gives the desired result in livescript
  2 件のコメント
Pierre
Pierre 2020 年 7 月 18 日
編集済み: Pierre 2020 年 7 月 18 日
PERFECT !
clf
x=linspace(0*deg,360*deg,300);
f='sqrt(abs(sin(x.^2)))'; ff = eval(f);
disp(str2sym(f));
So simple, sometimes we're almost ashamed to have asked such a simple question but I am sure some people will add it to check mistakes in there big equations.
madhan ravi
madhan ravi 2020 年 7 月 18 日
You don’t have to be ashamed of asking a question. By the way please don’t use eval() it’s completely unnecessary.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by