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!

 Accepted Answer

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

2 Comments

Thanks!
Good point to also be able to use cell string array...still doc ought to point it out for the newbie...

Sign in to comment.

More Answers (2)

dpb
dpb on 30 Jul 2013
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 on 30 Jul 2013
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!