필터 지우기
필터 지우기

How do I use text for ticks on X axis?

조회 수: 284 (최근 30일)
Sandy
Sandy 2014년 4월 9일
댓글: dpb 2021년 7월 22일
I have a loop that gives a variable a different name:
EX
i = 1;
while i < 5
if i == 1
name = 'CRHS';
elseif i == 2
name ='ELLY';
elseif i == 3
name = 'LGWD';
elseif i ==4
name = 'ECFS';
elseif i ==5
name = 'THMS';
end
i = i + 1;
end
I want to plot a figure using the 'name' variable as the corresponding X tick. For example for tick 1, use 'CRHS', tick 2 use 'ELLY', etc.
How can I do this?

채택된 답변

dpb
dpb 2014년 4월 9일
names = {'CRHS'; 'ELLY'; 'LGWD'; 'ECFS'; 'THMS'};
plot(...
set(gca,'xtick',[1:5],'xticklabel',names)
Set the tick values vector to appropriate numerical values dependent on the axis limits, of course. I just used the position values for demo porpoises...
  댓글 수: 9
Jack
Jack 2021년 7월 22일
Is there any way to label all the tics but dynamically display them? For example you label x points 1:10 but if the plot is sized down by the user, some of the labels dissapears to fit? Similar to the default functionality matlab has with automatic axis resizing
dpb
dpb 2021년 7월 22일
Once you write the tick labels manually you've broken the link between the tick marks and the tick labels; no automagic updating will happen after that.
You would have to write callback routines to handle the tick labels to go along with the ticks as wanted.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by