How to use gca handles to change xtick properties

조회 수: 5 (최근 30일)
Alexander Greene
Alexander Greene 2016년 8월 11일
댓글: Pham Dang 2016년 8월 12일
I am using MATLAB 2016, and I still can't figure out or find helpful documentation for how to change gca's xtick object. When I run my code I see the results in the command window, but when I plot it I see no change in my graph. Here is my code..
x = [0:0.001:(2*pi)]; y = (sin(x)).^2; figure(1) plot(x,y,'r') xlim([0 (2*pi)]); ax = gca; ax.XTick = [0 pi 2*pi]
Am I missing anything?

답변 (1개)

Pham Dang
Pham Dang 2016년 8월 11일
Hi, you should use the set command to set your Xtick property.
set(gca,'Xtick',[0 pi 2*pi])
  댓글 수: 2
Alexander Greene
Alexander Greene 2016년 8월 11일
I tried that and got this error
Function 'subsindex' is not defined for values of class 'struct'.
Error in handlesPractice (line 6)
Is there anything else I may be missing?
Pham Dang
Pham Dang 2016년 8월 12일
Hi, the exact following code works for me :
x = [0:0.001:(2*pi)];
y = (sin(x)).^2;
plot(x,y,'r');
xlim([0 (2*pi)]);
set(gca,'Xtick',[0 pi 2*pi])
(The subsindex function is not used in those lines. Are you calling it for a specific purpose ?)

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

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by