Stairs Command MATLAB Ends

Is it possible to put a circle at the end of the stairs function? If the value is 0 and each end, one cannot see where it starts.

 Respuesta aceptada

sixwwwwww
sixwwwwww el 18 de Oct. de 2013
Editada: sixwwwwww el 18 de Oct. de 2013

0 votos

Dear T,
I think you can do as follows (If i understood correctly)
figure
X = linspace(0,4*pi,40);
Y = sin(X);
stairs(X, Y), hold on
plot(X(end), Y(end), 'ro', 'linewidth', 2)
Or maybe you can use different color for next stairs to see difference between two series.
I hope it helps. Good luck!

16 comentarios

T
T el 22 de Oct. de 2013
Suppose I want to do the same thing with:
plotyy(x1,y1,x2,y2,@stairs, @plot);
How would I be able to modify it in this case?
sixwwwwww
sixwwwwww el 22 de Oct. de 2013
In this case you can do like this:
X1 = linspace(0,4*pi,40);
Y1 = sin(X1);
X2 = linspace(4*pi, 8*pi, 40);
Y2 = sin(X2);
x = [X1(end) X2(end)];
y = [Y1(end) Y2(end)];
plotyy(X1, Y1, X2, Y2, @stairs, @plot), hold on
plot(x, y, 'ro', 'linewidth', 2)
Good luck!
T
T el 23 de Oct. de 2013
Suppose instead the red circles are on the stairs function:
X1 = linspace(0,4*pi,40);
Y1 = sin(X1);
X2 = linspace(4*pi, 8*pi, 40);
Y2 = sin(X2);
x = [X1 X2];
y = [Y1 Y2];
plotyy(X1, Y1, X2, Y2, @stairs, @plot), hold on
plot(x, y, 'ro', 'linewidth', 2)
I have an edit box that moves the stairs function to the right. My issue is that it keeps duplicating the plot. I only want it to appear once.
I tried experimenting with a check box but the issue still arises.
sixwwwwww
sixwwwwww el 23 de Oct. de 2013
Can you show me your full code?
T
T el 23 de Oct. de 2013
The issue arises with these two lines:
hold on
plot(x, y, 'ro', 'linewidth', 2)
The fact that, once plotted, it remains on the figure.
I need to find a way to update it so that it plots only after translation.
sixwwwwww
sixwwwwww el 23 de Oct. de 2013
In this case you need to update these values:
x = [X1(end) X2(end)];
y = [Y1(end) Y2(end)];
before using
hold on
plot(x, y, 'ro', 'linewidth', 2)
then it will work again. Can you check it now?
T
T el 23 de Oct. de 2013
That's right. But after I translate it to the right, the previous plot will remain and it will duplicate it again, but to the right. So now you have two plots with red circles. I just want the later one.
sixwwwwww
sixwwwwww el 23 de Oct. de 2013
x = [X2(end)];
y = [Y2(end)];
here X2(end) and Y2(end) are the values for the sifted plot. Then use
hold on
plot(x, y, 'ro', 'linewidth', 2)
It will just plot one red circle at the end of the second graph which you need(if I understood correctly)
T
T el 23 de Oct. de 2013
I guess we should forget this idea of having a second function.
I think I should stick with the checkbox feature.
Suppose I apply the following:
x = [X2];
y = [Y2];
hold on
plot(x, y, 'ro', 'linewidth', 2)
If on produces the above, how would I remove it if I unchecked the checkbox?
sixwwwwww
sixwwwwww el 23 de Oct. de 2013
For this purpose you can clear the graphic object using
clf
when state of checkbox is changed and then you can re-plot the graph without red circles i.e. don't use
hold on
plot(x, y, 'ro', 'linewidth', 2)
after plotting the original graph.
For more information about "clf" see http://www.mathworks.de/de/help/matlab/ref/clf.html
T
T el 23 de Oct. de 2013
clf will clear my entire GUI so that is not an option for me.
Azzi Abdelmalek
Azzi Abdelmalek el 23 de Oct. de 2013
Editada: Azzi Abdelmalek el 23 de Oct. de 2013
You can use
cla
T
T el 23 de Oct. de 2013
This is close.
hold on
cla
plot(x, y, 'ro', 'linewidth', 2)
Will not plot the stairs function but only the red circles. When I shift, it only plot once which is what I want but the stairs is missing.
sixwwwwww
sixwwwwww el 23 de Oct. de 2013
use
stairs(x, y)
to plot stairs and then if you again need red circle at the end. Again use
hold on
plot(x(end), y(end), 'ro', 'linewidth', 2)
The logic remains the same always that every time you want to over write the plot using state of checkbox. Use the following commands in the sequence:
cla
stairs(x, y)
hold on
plot(x(end), y(end), 'ro', 'linewidth', 2)
T
T el 23 de Oct. de 2013
Now the issue that arises is not only does unchecking the box off removes the stairs function, but there is also the issue of changing the axes when using the plot.
Is there a better alternative?
sixwwwwww
sixwwwwww el 24 de Oct. de 2013
How you want to change the axis when you plot? Can you provide some screen shots what you need and what are you getting right now?

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 18 de Oct. de 2013
Editada: Azzi Abdelmalek el 18 de Oct. de 2013

0 votos

x=1:10
y=[0 1 0 1 0 1 0 1 0 1]
stairs(x,y,'k')
hold on
scatter(x,y,'or','linewidth',2)
%you can also change ylim
ylim([0 1.5])

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

T
T
el 18 de Oct. de 2013

Comentada:

el 24 de Oct. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by