MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Thread Subject: Putting text containing variables into plot

Subject: Putting text containing variables into plot

From: Kian

### Kian

Date: 24 Apr, 2013 18:32:09

Message: 1 of 4

How can I put a text into my plot which passes computed values in there?
For instance, I have computed my parameters to be:

pars =
0.0005 42.1963

Now I want to put a text in an appropriate position in my plot (where it does not block the figure content), and pass pars(1) and pars(2) in there.

My formula is omega(d) = exp(-pars(1)*d^pars(2))

So, I want to have Matlab to put that for me in the plot as:

omega(d) = exp(-0.0005*d^pars(2))

I have already tried to put it in the title by:
title([ '\omega(d)=exp (' , num2str(pars(1),'%4.5f') , ' d^' , (num2str(pars(2))), ')' ])

But still, the problem is pars(2) is not completely powered, and only its first digit (4) is powered.

I am really interested to put it rather as a text somewhere in my plot.

I appreciate any help.

Subject: Putting text containing variables into plot

From: Nasser M. Abbasi

### Nasser M. Abbasi

Date: 24 Apr, 2013 18:49:50

Message: 2 of 4

On 4/24/2013 1:32 PM, Kian wrote:
> How can I put a text into my plot which passes computed values in there?
> For instance, I have computed my parameters to be:
>
> pars =
> 0.0005 42.1963
>
> Now I want to put a text in an appropriate position in my plot (where it does not block the figure content), and pass pars(1) and pars(2) in there.
>
> My formula is omega(d) = exp(-pars(1)*d^pars(2))
>
> So, I want to have Matlab to put that for me in the plot as:
>
> omega(d) = exp(-0.0005*d^pars(2))
>
> I have already tried to put it in the title by:
> title([ '\omega(d)=exp (' , num2str(pars(1),'%4.5f') , ' d^' , (num2str(pars(2))), ')' ])
>
> But still, the problem is pars(2) is not completely powered, and only its first digit (4) is powered.
>
> I am really interested to put it rather as a text somewhere in my plot.
>
> I appreciate any help.
>

Use Latex to setup the string? ie use 'Interpreter', 'Latex'

Examples

Subject: Putting text containing variables into plot

From: Kian

### Kian

Date: 24 Apr, 2013 19:37:08

Message: 3 of 4

"Nasser M. Abbasi" wrote in message <kl99gc$42l$1@speranza.aioe.org>...
> On 4/24/2013 1:32 PM, Kian wrote:
> > How can I put a text into my plot which passes computed values in there?
> > For instance, I have computed my parameters to be:
> >
> > pars =
> > 0.0005 42.1963
> >
> > Now I want to put a text in an appropriate position in my plot (where it does not block the figure content), and pass pars(1) and pars(2) in there.
> >
> > My formula is omega(d) = exp(-pars(1)*d^pars(2))
> >
> > So, I want to have Matlab to put that for me in the plot as:
> >
> > omega(d) = exp(-0.0005*d^pars(2))
> >
> > I have already tried to put it in the title by:
> > title([ '\omega(d)=exp (' , num2str(pars(1),'%4.5f') , ' d^' , (num2str(pars(2))), ')' ])
> >
> > But still, the problem is pars(2) is not completely powered, and only its first digit (4) is powered.
> >
> > I am really interested to put it rather as a text somewhere in my plot.
> >
> > I appreciate any help.
> >
>
>
> Use Latex to setup the string? ie use 'Interpreter', 'Latex'
>
> Examples
>
>
> It worked out! Thank you!

 Subject: Putting text containing variables into plot From: Steven_Lord Date: 24 Apr, 2013 21:10:42 Message: 4 of 4 "Kian " wrote in message news:kl98f9$qkq$1@newscl01ah.mathworks.com... > How can I put a text into my plot which passes computed values in there? > For instance, I have computed my parameters to be: > > pars = > 0.0005 42.1963 > > Now I want to put a text in an appropriate position in my plot (where it > does not block the figure content), and pass pars(1) and pars(2) in there. > > My formula is omega(d) = exp(-pars(1)*d^pars(2)) > > So, I want to have Matlab to put that for me in the plot as: > > omega(d) = exp(-0.0005*d^pars(2)) > > I have already tried to put it in the title by: > title([ '\omega(d)=exp (' , num2str(pars(1),'%4.5f') , ' d^' , > (num2str(pars(2))), ')' ]) > > But still, the problem is pars(2) is not completely powered, and only its > first digit (4) is powered. Yes. You will need to group the string representation of the number in curly braces in order for TeX to treat it all as the text that should be included in the superscript. Compare: title('x^{17} and y^17') -- Steve Lord slord@mathworks.com To contact Technical Support use the Contact Us link on http://www.mathworks.com