How can I keep figure boxes from popping up while running script.
Show older comments
I am very new to MATLAB and programming in general, so please bear with my syntax/poor code.
I am trying to make an animation for my project in an introductory MATLAB class. I want to show how different sorts "look" as they are being processed. I have the script doing what I want, but I can't get it to stop opening new figure windows for each loop pass. This results in hundreds of windows being opened.
Here is the bubble sort for example.
Ba=input('Array to be sorted: ')
n=length(Ba)
c=[1:length(Ba)]
counter1=1
for y=1:n-1
for x=1:n-1
if Ba(x+1)<Ba(x)
temp=Ba(x);
Ba(x)=Ba(x+1);
Ba(x+1)=temp;
counter1=counter1+1
figure('Visible','off');
bar(c,Ba);
saveas(gcf, sprintf('name%d', counter1), 'bmp');
end
end
end
It saves the images to be made into an animation later, but it is very slow as it opens hundreds of windows.
Accepted Answer
More Answers (1)
Sean de Wolski
on 1 Aug 2013
0 votes
Instead of making a new figure window on each loop iteration, use clf to clear the current one and reuse it!
Categories
Find more on Loops and Conditional Statements 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!