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

3 views (last 30 days)
hgrlk on 26 Jul 2021
Commented: dpb on 28 Jul 2021
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.
dpb on 26 Jul 2021
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 on 26 Jul 2021
Edited: dpb on 26 Jul 2021
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!!!
dpb on 28 Jul 2021
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.

R2020b

### Community Treasure Hunt

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

Start Hunting!