Setting Axis scale steps

조회 수: 89 (최근 30일)
Youssef Darwich
Youssef Darwich 2020년 6월 14일
댓글: Shawn 2025년 11월 5일
Hello guys,
I'am new to Matlab and need your help
how can i set the axis such that every step is for example '8.03 units'?
thanks
  댓글 수: 1
Shawn
Shawn 2025년 11월 5일
To set the axis ticks with a specific step size like 8.03 units, you can use the xticks (or yticks) function. Here’s a quick example for the x-axis:
x_min = 0; % starting value of the axis
x_max =
100; % ending value of the axis (adjust as needed)
step =
8.03; % your desired step size
xticks(x_min:step:x_max);
This will set the ticks at intervals of 8.03 units along the x-axis. You can do the same for the y-axis with yticks. @mr flip

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

채택된 답변

Aditya Verma
Aditya Verma 2020년 6월 14일
편집: Aditya Verma 2020년 6월 14일
Hello,
You can set the x-axis ticks using xticks function:
x = 0:0.1:5;
plot(x, sin(x));
xticks(0:0.83:5);
xlim([0 5]);
In a similar way you can set your y or z ticks. You can read more about it here: https://www.mathworks.com/help/matlab/ref/xticks.html
  댓글 수: 2
Youssef Darwich
Youssef Darwich 2020년 6월 14일
thanks this was very helpful :) but i think "xlim()" function is trivial becaus the boundaries are already limited by the "xticks()" function, what do you think?
Aditya Verma
Aditya Verma 2020년 6월 15일
편집: Aditya Verma 2020년 6월 15일
The boundaries are limited by the extreme points of x which can be changed by xlim(). xticks() merely specifies a list of increasing values where the ticks should be marked, it could be out of the figure frame too! Consider the following example:
x = [4 2 6 0 -2];
plot(x, sin(x));
xticks([-4 8 10]);
You can hold and drag the graph to see those ticks.
I used xlim() because somehow 0 was being trimmed out from the graph at that moment, but now it's working fine :)

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

추가 답변 (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