How can I specify axis spacing?

I have X axis data from 15 to 30. By default it has spacing of 5, like 15,20,25,30. I want to specify spacing of 2, like 15,17,19 and so on. How can I do that? Can I use Xtick and y tick for it ? Thanks.

 採用された回答

Jan
Jan 2017 年 2 月 23 日

6 投票

AxesH = axes('Xlim', [15, 30], 'XTick', 15:2:30, 'NextPlot', 'add');
plot(15:30, rand(1, 16));

2 件のコメント

kanyvt
kanyvt 2017 年 2 月 24 日
Thanks, it helped.
Stelios Fanourakis
Stelios Fanourakis 2019 年 5 月 13 日
Hi. How can someone estimate the average of y values for every interval of the x axis as you state it?

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

その他の回答 (3 件)

Image Analyst
Image Analyst 2017 年 2 月 23 日

12 投票

If you have R2016b you can use the new xticks function:
xticks(15:2:30);
yticks(0:5:100); % Whatever....
Or with versions R2014b - R2016a:
ax=gca
ax.XTick = 15:2:30;
ax.YTick = 0:5:100;

3 件のコメント

kanyvt
kanyvt 2017 年 2 月 23 日
Thanks but unfortunately mine is MATLAB 2014a
Kamil Haziq
Kamil Haziq 2018 年 3 月 22 日
How to do the same thing for time variables? For example from 00:00:00 to 01:00:00 . I want it to be in 15 minute intervals. 00:15:00 00:30:00 and so on.
kanyvt
kanyvt 2018 年 3 月 25 日
編集済み: Image Analyst 2018 年 3 月 25 日
Hey Kamil,
Can you send the pic/image of your graph? I will take a look and try to help.
Thanks,

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

Geoff Hayes
Geoff Hayes 2017 年 2 月 23 日

2 投票

kanyvt - see specify axis tick values for details on how to set the ticks and labels.
A N
A N 2018 年 5 月 19 日

0 投票

I've got other question. I've got chart of bending moments of the beam. Between x=0 and x=0.6 the moments are described by the parabolic function. But in the chart it seems like a linear function. How can I specify (make smaller) distance betweeen YTicks or change units on Y-Axis to make clear that is quadratic function of bending moments? %set(gca,'ytick',[-0.27:0.05:0.02]) or something like that doesn't help.

6 件のコメント

Geoff Hayes
Geoff Hayes 2018 年 5 月 22 日
AN - please post this as a comment to the above question or as a new question. Do not use the answer option to ask a new question...
Marcelo Andrés Acuña
Marcelo Andrés Acuña 2019 年 10 月 31 日
I found this way:
xticks(8:2:20); % Spaces = 2
yticks(-0.5:0.1:0.5); %Spaces = 0.1
axis([8 20 -0.5 0.5]) %View axis
Ibrahim Elayan
Ibrahim Elayan 2020 年 4 月 13 日
編集済み: Image Analyst 2020 年 4 月 14 日
Good day
How can i get this FORM of spacing on x axis and y axis in certain interval and other interval keep in normal spacing?
Geoff Hayes
Geoff Hayes 2020 年 4 月 14 日
Ibrahim - what do you consider to be normal spacing?
P Velani
P Velani 2022 年 1 月 29 日
@Ibrahim Elayan: Issue is of not plotting but of computaion. Compute X and Y values at closer interval.
e.g. If X = 1:10 and you have Y = X^2 the plot will look linear. Instead try X =1:0.1:10 and plot it you will find more accurate curve compare to earlier.
I hope this will help you.
Image Analyst
Image Analyst 2022 年 1 月 29 日
@Ibrahim Elayan, try this:
period = 0.1
t = linspace(0, 0.675, 1008);
% Prepare amplitude. Goes from 2.5 to 1 during the first period
% then is 1 after that.
amplitude = ones(1, length(t)); % Initize
p1 = round(length(t)/6);
amplitude(1:p1) = linspace(2.5, 1, p1);
% Make signal.
y = amplitude .* sin(2 * pi * t / period);
% Plot signal
plot(t, y, 'b-', 'LineWidth', 2);
grid on;
xlabel('t');
ylabel('y');

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

カテゴリ

質問済み:

2017 年 2 月 23 日

コメント済み:

2022 年 1 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by