Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Very Difficult MatLab Problem

Subject: Very Difficult MatLab Problem

From: MatthewB

Date: 3 Jul, 2008 19:48:45

Message: 1 of 2

Hi,

I have a complicated legend in which I want to incorporate a quantity
with a hat over it. I read the previous responses to this question for
this ng and also on the web,
but could not get them to work for me.

My legend has the form

legend('Spectrum',['\gamma \approx' num2str(gval)],['\alpha \approx'
num2str(aval)])

So I want to have 3 entries in my legend: one is just a string and the
other 2 have strings and also numerical values computed in my program
(which are converted to strings). I want to put a hat over the gamma
in the second string.

What I've tried are the following variations, based on previous posts
asking this question:

Variation 1:
legend('Spectrum',['\gamma \approx'
num2str(gval),'interpreter','latex'],['\alpha \approx' num2str(aval)])
Variation 2:
legend('Spectrum',['\gamma \approx' num2str(gval)],['\alpha \approx'
num2str(aval)],'interpreter','latex')
Variation 3:
dd=legend('Spectrum',['\gamma \approx' num2str(gval)],['\alpha
\approx' num2str(aval)])
set(dd,'interpreter','latex')

Each variation was tried with and without putting $ $ around the
string \gamma \approx.

Thanks for any help that you can provide,

Matt B

Subject: Very Difficult MatLab Problem

From: Jos

Date: 3 Jul, 2008 20:40:19

Message: 2 of 2

MatthewB <mathimagical@netscape.net> wrote in message
<e32561d9-819f-422f-b0f3-
d946a52fb21b@e39g2000hsf.googlegroups.com>...
> Hi,
>
> I have a complicated legend in which I want to
incorporate a quantity
> with a hat over it. I read the previous responses to this
question for
> this ng and also on the web,
> but could not get them to work for me.
>
> My legend has the form
>
> legend('Spectrum',['\gamma \approx' num2str(gval)],
['\alpha \approx'
> num2str(aval)])
>
> So I want to have 3 entries in my legend: one is just a
string and the
> other 2 have strings and also numerical values computed
in my program
> (which are converted to strings). I want to put a hat
over the gamma
> in the second string.
>
> What I've tried are the following variations, based on
previous posts
> asking this question:
>
> Variation 1:
> legend('Spectrum',['\gamma \approx'
> num2str(gval),'interpreter','latex'],['\alpha \approx'
num2str(aval)])
> Variation 2:
> legend('Spectrum',['\gamma \approx' num2str(gval)],
['\alpha \approx'
> num2str(aval)],'interpreter','latex')
> Variation 3:
> dd=legend('Spectrum',['\gamma \approx' num2str(gval)],
['\alpha
> \approx' num2str(aval)])
> set(dd,'interpreter','latex')
>
> Each variation was tried with and without putting $ $
around the
> string \gamma \approx.
>
> Thanks for any help that you can provide,
>
> Matt B


Try this:

plot(rand(3)) ;
MyValue = 2*pi ;
legend({sprintf('$\\hat{\\gamma} \\approx %.2f$',
MyValue),'BB', 'ABCDEF'}, 'interpreter', 'latex')

Carefully note
1) the positioning of the curly braces, so that the first
argument specifies the three legend captions.
2) the use of sprintf to generate a string,
3) the use of double backslashes (\\) to circumvent escape
sequences for sprintf

hth
Jos

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics