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.

카테고리

도움말 센터File Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by