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:
Percent Format

Subject: Percent Format

From: kbr

Date: 27 Jun, 2010 01:22:06

Message: 1 of 6

Hello,

I have a bar plot with x-axis labels showing as 0.04, 0.06, 0.08, etc. How do I change these to 4%, 6%, 8%, etc.

Also, how do I show more digits to the right of the decimal? ie: 4.0% vs 4%?

Thanks!

Subject: Percent Format

From: Faraz Afzal

Date: 27 Jun, 2010 01:49:04

Message: 2 of 6

"kbr" <karlruff@yahoo.com> wrote in message <i0693u$io7$1@fred.mathworks.com>...
> Hello,
>
> I have a bar plot with x-axis labels showing as 0.04, 0.06, 0.08, etc. How do I change these to 4%, 6%, 8%, etc.
>
> Also, how do I show more digits to the right of the decimal? ie: 4.0% vs 4%?
>
> Thanks!

Hi Karl

after plotting your bar graph just use this and ur problem is solved..

set(gca,'XTickLabel','4.000%|6.000%|8.000%|10.000%')

Thats it.. I hope it helps.. Forget not to say Thanks..

regards,
Muhamamd Faraz

Subject: Percent Format

From: dpb

Date: 27 Jun, 2010 01:54:41

Message: 3 of 6

kbr wrote:
> Hello,
>
> I have a bar plot with x-axis labels showing as 0.04, 0.06, 0.08, etc.
> How do I change these to 4%, 6%, 8%, etc.
>
> Also, how do I show more digits to the right of the decimal? ie: 4.0% vs
> 4%?

There may be an easier way I'm not thinking of but...

t = get(gca,'xticklabel'); % retrieve current labels
v = str2num(v)*100; % convert to percent numeric values
t = num2str(v,'%.1f%%', v); % convert to char array w/ % sign
set(gca,'xticklabel', t); % and write new labels

Salt to suit...

--

Subject: Percent Format

From: ImageAnalyst

Date: 27 Jun, 2010 02:10:33

Message: 4 of 6

Shouldn't that be
v = str2num(t)*100; ???

Subject: Percent Format

From: dpb

Date: 27 Jun, 2010 03:41:26

Message: 5 of 6

ImageAnalyst wrote:
> Shouldn't that be
> v = str2num(t)*100; ???

Indeed...

--

Subject: Percent Format

From: dpb

Date: 27 Jun, 2010 03:44:20

Message: 6 of 6

dpb wrote:
...

> t = num2str(v,'%.1f%%', v); % convert to char array w/ % sign
...

t = num2str(v,'%.1f%%'); % an extra "v" in there, too, ...

--

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