Aliaa Abdelnasser
Aliaa Abdelnasser

Reputation: 19

Repeating numbers in x-axis matlab plot

IEF % is a matrix have negative and positive values (1441 X 1)
T=linspace(0,24,1441);
figure,
plot(T,IEF)
grid on
set(gca,'xticklabel', 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24)

This code gave me a figure with x-axis sequence from 0 to 24 (hours) but the data is of five days so I need to repeat 0 to 24 five times on the X-axis.

How can I do that?

Upvotes: 0

Views: 653

Answers (1)

Adriaan
Adriaan

Reputation: 18177

I suggest not plotting 24*5=120 numbers, as that'd pretty much mess up your plot. Either let MATLAB take its course using the default, or set something like:

set(gca,'xticklabel', 0:24) %// for 24 hours, shorter of what you had above
set(gca,'xticklabel', 0:120) %// for 5 days
set(gca,'xticklabel', 0:6:120) %// for 5 days in steps of 6 hours

If you want to use actual 24 hours and not 0 to 120 hours, use repmat:

TimeHour = 0:6:24;
Time24Hour = 0:24;
TICKLABEL = repmat(TimeHour,1,5); %// change the 5 to how many days you want
TICKLABEL24 = repmat(Time24Hour,1,5); %// utilises 0:24 five times
set(gca,'xticklabel', TICKLABEL)
set(gca,'xticklabel', TICKLABEL24)

Upvotes: 1

Related Questions