Print a Matlab Expression as Text

Hey,
I am creating a GUI in which I would like to display an equation as text.
For example, I have the expression:
z = (z).^2+c;
I would like to print the '(z).^2+c' part of this expression so the user knows which equation is selected.
Is this possible to do?
Thanks,
Ben G

7 件のコメント

dpb
dpb 2019 年 12 月 24 日
Where is this expression coming from and how is it presently stored?
If it is an equation/expression in a text field input by the user, for example, then
>> xpr='z = (z).^2+c;';
>> sprintf(strtrim(xpr(strfind(xpr, '=')+1:end)))
ans =
'(z).^2+c;'
>>
Image Analyst
Image Analyst 2019 年 12 月 24 日
Maybe try echo???
echo on;
z = (z).^2+c;
echo off
Lines of code that are executed while echo is on will display in the command window.
Benjamin Gutierrez
Benjamin Gutierrez 2019 年 12 月 24 日
@dpb currently the expresson is hard coded into the program. The 'user' has to uncomment the desired equation. It is this uncommented hard coded equation which I would like to display in the GUI.
However, I eventually want to enable the user to input their own equation, so I may just implement your solution.
Thanks!
Walter Roberson
Walter Roberson 2019 年 12 月 24 日
str2func() to move from a character vector to a function handle.
Benjamin Gutierrez
Benjamin Gutierrez 2019 年 12 月 25 日
Thank you everyone for the responses.
I ended up entering the expression as a string and using eval() to execute the expression.
I can then use the original string to display in my uicontrol text box using sprintf() like @dpb suggested.
Cheers,
Ben G
Walter Roberson
Walter Roberson 2019 年 12 月 25 日
str2func() is more robust than eval()
Benjamin Gutierrez
Benjamin Gutierrez 2019 年 12 月 25 日
Perfect, I'll switch to using that function.
Thank you.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

2019 年 12 月 23 日

コメント済み:

2019 年 12 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by