Update figure after each loop
10 views (last 30 days)
Show older comments
I created a circle plot and i want to draw lines on the circle based on user data. I want to refresh circle lines after every loop. E.g When i enter data for the first loop ,x=3,y=2,z=1,a=1 i want from figure to hold values from case (z=1 and a=1) (plot([0 1],[3 4.9],'b')) and for the second loop, z=1, a=2, i want the figure to be updated and give me lines from three plots :
plot([0 1],[3 4.9],'b');
plot([0 5],[6 4.9],'b');
plot([4 4],[4 4],'b');
How can i update the figure after every loop?
Below is my code
prompt=('Enter the primary features between 3 and 7: ');
x = input(prompt);
prompt=('Give the subfeatures:');
y=input(prompt);
t=0; %counter to terminate for
for i=1:x
prompt=('Give the position of the element:');
z=input(prompt);
prompt=('How many lines on this position?:');
a=input(prompt);
%prompt=('Give the subfeatures of the third layer:');
%n=input(prompt);
numPoints=100; %Number of points making up the circle
radius=5; %Radius of the circle
%Define circle in polar coordinates (angle and radius)
theta=linspace(0,2*pi,numPoints); %100 evenly spaced points between 0 and 2pi
rho=ones(1,numPoints)*radius; %Radius should be 1 for all 100 points
%Convert polar coordinates to Cartesian for plotting
[X,Y] = pol2cart(theta,rho);
%Plot a red circle
plot(X,Y,'r-','linewidth',2);
axis square
%Altering the radius allows us to plot a second circle within the first one
radius=7; %third circle
rho=ones(1,numPoints)*radius;
[X,Y] = pol2cart(theta,rho);
hold on
plot(X,Y,'k-','linewidth',2);
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (x==3 & y==2)
t=t+1 % counter
myfunc3();
hold on;
set(gcf,'visible','off')
if (t==2)
set(gcf,'visible','on')
end
switch z
case z==1 & a==1
if(t==2)
plot([0 1],[3 4.9],'b');
return
end
case z==1 & a==2
if(t==2)
plot([0 5],[6 4.9],'b');
plot([4 4],[4 4],'b');
return
end
end
end
0 Comments
Answers (1)
Bob Thompson
on 31 Jan 2019
I suspect that you are having a challenge because you activate 'hold on' right after myfunc3(), but you don't deactivate it. This means that during the next loop, when you plot your original red circle it is keeping all of the original plots, instead of removing and replotting the two circles. This means that you plot the first case in the first loop, and then have both the first and second cases plotted in the second loop. Try putting 'hold off' at the end othe loop.
Unfortunately, I cannot test this directly because I do not have myfunc3(). If you wanted to post that here I could run the further tests myself.
6 Comments
Bob Thompson
on 31 Jan 2019
If you want to have both cases, then remove all of the 'hold' commands, and replace them with a single 'hold on' command in front of the loop. Then you still need to replace the if statement to print the first line, but by the end both lines should be printed on the same plot.
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!