What does monotically increasing means?

7 visualizaciones (últimos 30 días)
jjlivestrong
jjlivestrong el 10 de Oct. de 2012
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?

Respuesta aceptada

Star Strider
Star Strider el 10 de Oct. de 2012
Editada: Star Strider el 10 de Oct. de 2012
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.

Más respuestas (1)

Matt Fig
Matt Fig el 10 de Oct. de 2012
Editada: Matt Fig el 10 de Oct. de 2012
Monotonically increasing means that each value is larger than the previous value.
Yes = [1 2 3 4 5 6]
No = [1 1 3 4 5 3]
If you do this:
D = diff(x)
you will get this result:
D == [1 0 1 0 1 1]
Since not every element of D is positive, x is not monotonically increasing.
Try this:
x1 = floor(now) + 7/24;% TODAY
x2 = x1 + .5;% TONIGHT
x3 = x1 + 1;% TOMORROW
x4 = x1 + 1.50;% TOMORROW_NIGHT
x5 = x1 + 2;% TWO_DAYS_FROM_TODAY
x6 = x1 + 3;% THREE_DAYS_FROM_TODAY
x7 = x1 + 4;% FOUR_DAYS_FROM_TODAY
x = [x1,x2,x3,x4,x5,x6,x7];
Now have a look:
datestr(x,0)
ans =
10-Oct-2012 07:00:00
10-Oct-2012 19:00:00
11-Oct-2012 07:00:00
11-Oct-2012 19:00:00
12-Oct-2012 07:00:00
13-Oct-2012 07:00:00
14-Oct-2012 07:00:00
  3 comentarios
Matt Fig
Matt Fig el 10 de Oct. de 2012
Daniel, I think you are correct for the mathematical definition, but not for the MATLAB definition.
close all
set(gca,'xtick',[0 .1 .2 .3 .4 .5])% No problem
pause(1)
close all
set(gca,'xtick',[0 .1 .2 .3 .3 .5])% Problem, and error...
Star Strider
Star Strider el 10 de Oct. de 2012
Matt, PlanetMath seems to agree with you (and MATLAB).

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by