how to adjust x-axis in plot

i want x-axis to be
30 is starting point
30 2 4 6 8 10 .... 30 2 4 6 8 10 .... 30 2 .....
like a once a month loop

回答 (2 件)

Arif Hoq
Arif Hoq 2022 年 3 月 23 日

0 投票

try repmat function:
A=[30 2 4 6 8 10];
no_of_rows=1;
no_of_repeated_times=3;
B=repmat(A,no_of_rows,no_of_repeated_times)
B = 1×18
30 2 4 6 8 10 30 2 4 6 8 10 30 2 4 6 8 10

3 件のコメント

peter huang
peter huang 2022 年 3 月 23 日
How to render it on the axes of the drawing?
Arif Hoq
Arif Hoq 2022 年 3 月 23 日
I dont get you. can you please explain more ? or any expected graph ?
Arif Hoq
Arif Hoq 2022 年 3 月 23 日
I guess you are talking about xtick
A=[30 2 4 6 8 10];
no_of_rows=1;
no_of_repeated_times=3;
B=repmat(A,no_of_rows,no_of_repeated_times);
% plot anything
x = 0:5:50*pi;
y = sin(x);
plot(x,y)
xticklabels(B)

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

Les Beckham
Les Beckham 2022 年 3 月 23 日
編集済み: Les Beckham 2022 年 3 月 23 日

0 投票

I think this is what you are asking for. Note that this isn't going to be very pretty if you have more than a couple of months to plot. And, of course, it doesn't account for varying numbers of days in a month.
plot(1:60)
xticks(1:2:60)
xticklabels(repmat([30 2:2:28], 1, 2))

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

質問済み:

2022 年 3 月 23 日

コメント済み:

2022 年 3 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by