How can I write division formula in label of matlab app designer?

53 次查看(过去 30 天)
Hello everyone,
I have a problem about my matlab app designer label thing. I want to write a formula in the label but I have parameters that calculated before. I use fuzzy in the app, thus I have parameters like for example K_4 = output4(1);
and I have a formula that is Precision Model function that contains these parameters. Precision Model,
this is the sample of the app and you can see the FH(s) function. We created this with labels and used division image,
I want to write this function in the label form without using divison image. I found something like
app.Label.Text = '$$\frac{( numerator}{denominator}';
app.Label.Interpreter = 'latex';
But I cannot find how I can write my calculated parameters in this? If I wrote K_4 for example (like app.Label.Text = '$$\frac{( K_4}{denominator}';), it gets this as string.
Can you help me please?
  3 个评论
hgrlk
hgrlk 2021-7-26
I think setting interpreter before or after doesnt matter to solve my problem. I cannot write my parameters as numeric form. If K_4 has a output as 25 for example, my code shows it as K_4 not in numeric form.
dpb
dpb 2021-7-26
编辑:dpb 2021-7-26
Well, you've got to write the string with compose or similar to substitute variables into the expression where they belong. It gets messy; write small pieces at a time and string them together to build to final result.
Another way to do such things is to build a template string that has embedded in it the space for a given size of number string and then do character substitution into those locations. That requires that the numbers will always fit into the given spaces, of course.
Start by getting a test expression to work with hardcoded numbers to work out the LaTex formula stuff; then you can work in the variables into that expression.
Good luck; my experiences w/ LaTex in MATLAB have been mostly frustrating ones...but I have no expertise in the area.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2021-7-26
编辑:dpb 2021-7-26
The above LaTex string is bad syntax -- here's a simplified illustration of what is needed -- your expression is far more complex; I'm not even going to attempt to encode it. Not that it's not doable, it's just a lot of tedium.
I'll illustrate writing a variable into an output string that will write a fraction --
fracfmt='$$\\frac{%.2f}{%s}$$'; % format template -- numerator a number, denominator a string
num=pi; % variables holding numerator to plug into format - numeric
den='\pi'; % and string is what is expected by format expression
strtowrite=sprintf(fracfmt,num,den); % build a fraction string with numerator, denominator
hAx=axes; % an axes object
hAx.XLabel.Interpreter='latex'; % set interpreter
xlabel(strtowrite) % and write our fancy string there...
This results in
Your mission, should you choose to undertake it, is to write the appropriate formatting string into which you can insert the necessary variables' values by use thereof as illustrated.
It can be whatever it needs be, of course, I just illustrated one small piece; depending upon how much of the above equation you intend to make dynamic, it could be a bunch of values must be passed.
NB: The example code you posted is bad syntax -- perhaps you tried to just copy a subsection of a much longer expression, but it has a spurious "(" in the beginning and is missing the closing matching "$$"
Then there's the deal about whether to use "$" or "$$" that has to do with internals of LaTeX beyond what I understand the difference -- other than I note that if use only single "$" here, the font size is much smaller for some reason.
All that is for a LaTeX guru, not i...
Good luck, undoubtedly you'll need it and much patience!!!
  5 个评论
dpb
dpb 2021-7-28
编辑:dpb 2021-7-28
You can string together as many and whatever formatting strings you need in whatever order and with what other literal text is wanted/needed. You just need to then pass the right number and type of arguments to match.
See <formatting-strings> for all the details. You are not limited in any way in number and/or type and/or ordering in any given formatting string up to the limit of complexity you can manage to keep straight--hence the suggestion to build up complex expressions piecewise instead of trying to do all at once.
K=0.95; M=7.0493; E=-1.14;
fmt=['%0.2f*{%0.3fs + 1)*exp(%0.2fs)'];
s=sprintf(fmt,K,M,E)
To this, of course, you have to also insert the proper LaTex commands in the proper order to control fonts, etc., etc., -- like undoubtedly you would want to write the exponential as e with a superscripted exponent expression rather than as expanded text.
Again, it's all doable, but will be tedious to build the templates. But, as long as the form of the equation doesn't change, once it's built it's trivial to pass different numbers in; it's building and debugging the template that's the challenge--which again, is just tedious paying attention to the details and ensuring keep proper overall LaTeX syntax so the interpreter can parse it.
dpb
dpb 2021-7-28
K=0.95; M=7.0493; E=-1.14;
fmt=['$$%0.2f*(%0.3fs + 1)*e\\textsuperscript {%0.2fs}$$'];
s=sprintf(fmt,K,M,E);
hAx=axes;
hTxt=text(0.1,0.7,s,'interpreter','latex');
produced
which exceeds my knowledge of LaTeX -- I had to look up \textsuperscript. Hopefully you're well acquainted with it.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Word games 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by