Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
clabel tags

Subject: clabel tags

From: DickV Vieira

Date: 5 Feb, 2009 19:44:02

Message: 1 of 6

Hi
I am plotting a figure through contourc. In order to make a proper legend for the level curves I have adopted the command clabel as follows,

[C,h] =contour(X_axis,Y_axis,round(1e-3*sigma_x),20);
text_handle = clabel(C),h)
set(text_handle,'BackgroundColor',[1 1 .6],...
    'Edgecolor',[.7 .7 .7]);

However, the numerical information appearing in the plot has too many digits. How should I proceed in order to round the plotted text into an integer format?

Thanks,

Subject: clabel tags

From: Aurelien Queffurust

Date: 6 Feb, 2009 09:23:01

Message: 2 of 6

"DickV Vieira" <rjfm.vieira@gmail.com> wrote in message <gmffi2$q3d$1@fred.mathworks.com>...
> Hi
> I am plotting a figure through contourc. In order to make a proper legend for the level curves I have adopted the command clabel as follows,
>
> [C,h] =contour(X_axis,Y_axis,round(1e-3*sigma_x),20);
> text_handle = clabel(C),h)
> set(text_handle,'BackgroundColor',[1 1 .6],...
> 'Edgecolor',[.7 .7 .7]);
>
> However, the numerical information appearing in the plot has too many digits. How should I proceed in order to round the plotted text into an integer format?
>
> Thanks,

To work around this issue, one can use the SPRINTF function to control the precision of the numeric value displayed.

Subject: clabel tags

From: Matej

Date: 20 Feb, 2009 10:59:02

Message: 3 of 6

"Aurelien Queffurust" <tug83@yahoo.fr> wrote in message <gmgvhl$3p4$1@fred.mathworks.com>...
> "DickV Vieira" <rjfm.vieira@gmail.com> wrote in message <gmffi2$q3d$1@fred.mathworks.com>...
> > Hi
> > I am plotting a figure through contourc. In order to make a proper legend for the level curves I have adopted the command clabel as follows,
> >
> > [C,h] =contour(X_axis,Y_axis,round(1e-3*sigma_x),20);
> > text_handle = clabel(C),h)
> > set(text_handle,'BackgroundColor',[1 1 .6],...
> > 'Edgecolor',[.7 .7 .7]);
> >
> > However, the numerical information appearing in the plot has too many digits. How should I proceed in order to round the plotted text into an integer format?
> >
> > Thanks,
>
> To work around this issue, one can use the SPRINTF function to control the precision of the numeric value displayed.

I don't understand this to much. How can I use sprintf inside clabel? Can you post the code please?

Subject: clabel tags

From: Piotr Baniukiewicz

Date: 6 Apr, 2009 12:56:01

Message: 4 of 6

"Matej " <hramat@gmail.com> wrote in message <gnm2dm$s4n$1@fred.mathworks.com>...
> "Aurelien Queffurust" <tug83@yahoo.fr> wrote in message <gmgvhl$3p4$1@fred.mathworks.com>...
> > "DickV Vieira" <rjfm.vieira@gmail.com> wrote in message <gmffi2$q3d$1@fred.mathworks.com>...
> > > Hi
> > > I am plotting a figure through contourc. In order to make a proper legend for the level curves I have adopted the command clabel as follows,
> > >
> > > [C,h] =contour(X_axis,Y_axis,round(1e-3*sigma_x),20);
> > > text_handle = clabel(C),h)
> > > set(text_handle,'BackgroundColor',[1 1 .6],...
> > > 'Edgecolor',[.7 .7 .7]);
> > >
> > > However, the numerical information appearing in the plot has too many digits. How should I proceed in order to round the plotted text into an integer format?
> > >
> > > Thanks,
> >
> > To work around this issue, one can use the SPRINTF function to control the precision of the numeric value displayed.
>
> I don't understand this to much. How can I use sprintf inside clabel? Can you post the code please?

Here you have:

[C,h] = contour(ZI,10);
handle=clabel(C,h,'fontsize',12);
for a=1:length(handle)
    s = get(handle(a),'String'); % get string
    s = str2num(s); % convert in to number
    s = sprintf('%4.2f',s); % format as you need
    set(handle(a),'String',s); % place it back in the figure
end

Subject: clabel tags

From: Matej

Date: 6 Apr, 2009 14:25:03

Message: 5 of 6

>
> Here you have:
>
> [C,h] = contour(ZI,10);
> handle=clabel(C,h,'fontsize',12);
> for a=1:length(handle)
> s = get(handle(a),'String'); % get string
> s = str2num(s); % convert in to number
> s = sprintf('%4.2f',s); % format as you need
> set(handle(a),'String',s); % place it back in the figure
> end


thanx a lot

Subject: clabel tags

From: Rami

Date: 5 Jul, 2012 02:04:08

Message: 6 of 6

"Matej" wrote in message <grd3bv$s99$1@fred.mathworks.com>...
> >
> > Here you have:
> >
> > [C,h] = contour(ZI,10);
> > handle=clabel(C,h,'fontsize',12);
> > for a=1:length(handle)
> > s = get(handle(a),'String'); % get string
> > s = str2num(s); % convert in to number
> > s = sprintf('%4.2f',s); % format as you need
> > set(handle(a),'String',s); % place it back in the figure
> > end
>
>
> thanx a lot

Hi,

I would like to do the same thing, that is, change the format of the numbers, but for a manual contour.

clabel(C,h,'manual')

Thanks.

Tags for this Thread

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.

Contact us