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!

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 7 月 30 日

0 投票

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

2 件のコメント

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

サインインしてコメントする。

その他の回答 (2 件)

dpb
dpb 2013 年 7 月 30 日

0 投票

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 2013 年 7 月 30 日

0 投票

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