selective hold on plot

조회 수: 15 (최근 30일)
Abid Mehmood
Abid Mehmood 2019년 3월 1일
답변: Steven Lord 2019년 3월 4일
Hi,
I am doing lot of plots on a single figure and i want to hold on the selective plots and NOT all of plots. With MATLAB hold 'on' , it will make hold on all or none. Any work around?
Thanks,
  댓글 수: 1
Adam
Adam 2019년 3월 4일
Just keep the handles to each plot and delete them as appropriate yourself when conditions define that they should be removed.

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

답변 (2개)

Star Strider
Star Strider 2019년 3월 1일
It depends on what you want to do, of course.
One option is to simply put a condition on the hold call:
for k = 1:4
subplot(2,2,k)
plot(rand(1,10), rand(1,10), 'pb')
if rem(k,2) == 1
hold on
end
plot(rand(1,10)+1, rand(1,10)+1, 'pg')
hold off
end
I assume you are doing subplot calls or something similar.
  댓글 수: 1
Abid Mehmood
Abid Mehmood 2019년 3월 4일
I am working on the single plot with multiple curves e.g. single x-y plane with curves y1, y2, y3, y4 ... etc. All these plots are constantly updating and when a certain condition for y1 meets i want to "hold on" to y1. but when i do this it just hold on to everything. I know if i have multiple subplot then i can apply "hold on" on axes, but i don't have subplots. I tried to put all these curves on overlapping different axes so when i "hold on" one axes for let's say y1 and it shouldn't affect y2 and so forth. But that doesn't seems to work.

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


Steven Lord
Steven Lord 2019년 3월 4일
What do you mean when you say you want to '"hold on" to y1'? Do you want to do something like a zero order hold on the data? Or do you just want to skip the updating step for that particular curve?
Perhaps using animatedline objects would work. If a condition is met, just stop calling addpoints for that particular animatedline while the condition is satisfied. For example, adapting the example from the animatedline help text:
numpoints = 100000;
x = linspace(0,4*pi,numpoints);
y = sin(x);
figure
h = animatedline;
axis([0,4*pi,-1,1])
for k = 1:numpoints
% Skip y coordinates outside [-0.5, 0.5]
if abs(y(k)) <= 0.5
addpoints(h,x(k),y(k))
end
drawnow update
end
If you wanted the curve to continue drawing straight across the lines y = 0.5 and y = -0.5, you could use min and max to saturate the data to those bounds.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by