Issue with axis tick labels

Hi,
I'm trying to control the axis tick label. I'm looking at this solution on the mathworks website: http://www.mathworks.com/support/solutions/en/data/1-15HXQ/
At the very end this code is given:
plot(0:4,0:4)
set(gca,'XLim',[0 4])
set(gca,'XTick',[0:0.5:4])
set(gca,'XTickLabel',['0';' ';'1';' ';'2';' ';'3';' ';'4'])
However, I want to change the tick label to be in increments of 10. So I use:
set(gca,'XTickLabel',['0';' ';'10';' ';'20';' ';'30';' ';'40'])
and I get the following error:
"??? Error using ==> vertcat
CAT arguments dimensions are not consistent."
Any help would be appreciated. Thanks!

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 30 Jul. 2013

0 Stimmen

set(gca,'XTickLabel',{'0';' ';'10';' ';'20';' ';'30';' ';'40'})

2 Kommentare

Tyler
Tyler am 30 Jul. 2013
Thanks!
dpb
dpb am 30 Jul. 2013
Good point to also be able to use cell string array...still doc ought to point it out for the newbie...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

dpb
dpb am 30 Jul. 2013

0 Stimmen

set(gca,'XTickLabel',['0';' ';'10';' ';'20';' ';'30';' ';'40'])
The '0' and the ' ' aren't same length as the '10', etc.
Use char instead...
set(gca,'XTickLabel',char('0',' ','10',' ','20',' ','30',' ','40'))
It's a bad example that uses only 1-character labels that leads to such errors because it's only natural for users to presume the same thing will work in general. Suggest a documentation enhancement report would not be remiss.
Jan
Jan am 30 Jul. 2013

0 Stimmen

You can use the bar as separator also:
set(gca,'XTickLabel', '0| |10| |20| |30| |40')
In ancient Matlab version this has even been faster, but the modern Java GUI methods convert this internally to something like a cell string at first. But the timings will not really matter here.

Community Treasure Hunt

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

Start Hunting!

Translated by