MATLAB: What does monotically increasing means

plotsubplot

I am trying to write 1 set of two subplots that outputs forecast predictions, but I keep getting this error
??? Error using ==> set
Values must be monotonically increasing
Error in ==> borrame at 29
set(gca,'XTick',[x(1) x(2) x(3) x(4) x(5) x(6) x(7)])
The code goes like this,
ymin = [12 12 14 4 13 17 16];
ymax = [17 17 18 17 18 22 21];
ymin1 = [4 4 4 4 6 5 6];
ymax1 = [4 4 4 5 6 6 8];
x1 = floor(now) +7/24;% TODAY

x2 = floor(now + 0.50) +7/24;% TONIGHT

x3 = floor(now + 0.75) +7/24;% TOMORROW

x4 = floor(now + 1.50) +7/24;% TOMORROW_NIGHT

x5 = floor(now + 1.75) +7/24;% TWO_DAYS_FROM_TODAY

x6 = floor(now + 2.50) +7/24;% THREE_DAYS_FROM_TODAY

x7 = floor(now + 3.50) +7/24;% FOUR_DAYS_FROM_TODAY

x = [x1,x2,x3,x4,x5,x6,x7];
subplot(2,1,1);
plot(x,ymax,'-ks','MarkerFaceColor','k','LineWidth',2)
hold on
plot(x,ymin,'--ko','MarkerFaceColor','k','LineWidth',2)
datetick('x',1,'keepticks');
title('Wind(Knots) versus Time (dd-mmmm-yyyy)','fontsize',12,'fontweight','b','fontname','times');
xlabel('Time (dd-mmmm-yyyy)','fontweight','b','fontname','times');
set(gca,'XTick',[x(1) x(2) x(3) x(4) x(5) x(6) x(7)])
ylabel('Wind (Knots)','fontweight','b','fontname','times');
legend('Max','Min',2);
set(gca,'fontname','times') % Set it to times

grid minor
subplot(2,1,2);
plot(x,ymax1,'-ks','MarkerFaceColor','k','LineWidth',2)
hold on
plot(x,ymin1,'--ko','MarkerFaceColor','k','LineWidth',2)
datetick('x',1,'keepticks');
title('Waves (ft) versus Time (dd-mmmm-yyyy)','fontsize',12,'fontweight','b','fontname','times');
xlabel('Time (dd-mmmm-yyyy)','fontweight','b','fontname','times');
set(gca,'XTick',[x(1) x(2) x(3) x(4) x(5) x(6) x(7)])
ylabel('Waves (ft)','fontweight','b','fontname','times');
legend('Max','Min',2);
set(gca,'fontname','times') % Set it to times
grid minor
What I want is one set of two plots, and on the x-axis the variables be in this format,
x1 = datestr(floor(now) +7/24, 'ddd dd/mmm')% TODAY
x2 = datestr(floor(now + 0.50) +7/24, 'ddd dd/mmm')% TONIGHT
x3 = datestr(floor(now + 0.75) +7/24, 'ddd dd/mmm')% TOMORROW
x4 = datestr(floor(now + 1.50) +7/24, 'ddd dd/mmm')% TOMORROW_NIGHT
x5 = datestr(floor(now + 1.75) +7/24, 'ddd dd/mmm')% TWO_DAYS_FROM_TODAY
x6 = datestr(floor(now + 2.50) +7/24, 'ddd dd/mmm')% THREE_DAYS_FROM_TODAY
x7 = datestr(floor(now + 3.50) +7/24, 'ddd dd/mmm')% FOUR_DAYS_FROM_TODAY
Can you please help?

Best Answer

I suggest calculating your dates ( x vector ) this way:
ofst = [0.0; 0.5; 0.75; 1.50; 1.75; 2.50; 3.50]*24;
xnow = floor(now);
for k1 = 1:length(ofst)
x(k1,:) = addtodate(xnow, ofst(k1)+7, 'hour');
end
xchk = [x datevec(x)] % Optional, to be sure the dates are what you want
then to get the format in your datetick that you want, substitute this line:
datetick('x','ddd dd/mmm','keepticks');
for the datetick lines in your the code you posted. You don't need to change anything else.
Related Question