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.

 채택된 답변

sixwwwwww
sixwwwwww 2013년 10월 18일
편집: sixwwwwww 2013년 10월 18일

0 개 추천

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

T
T 2013년 10월 22일
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?
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 2013년 10월 23일
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 2013년 10월 23일
Can you show me your full code?
T
T 2013년 10월 23일
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.
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 2013년 10월 23일
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.
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 2013년 10월 23일
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?
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 2013년 10월 23일
clf will clear my entire GUI so that is not an option for me.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 23일
편집: Azzi Abdelmalek 2013년 10월 23일
You can use
cla
T
T 2013년 10월 23일
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.
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 2013년 10월 23일
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 2013년 10월 24일
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?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 18일
편집: Azzi Abdelmalek 2013년 10월 18일

0 개 추천

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])

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

질문:

T
T
2013년 10월 18일

댓글:

2013년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by