waitbar + surf functions. are they incompatible?

[EDIT: 20110621 14:54 CDT - reformat - WDR]
When trying to establish a waitbar for a double-cycle I am using, I have found out that it is not possible to run it simultaneously with the surf function.
Example:
aux = 0;
steps = length(stelement)*length(csplate);
progressbar = waitbar(0,'graphic under construction...');
for el = 1:length(stelement)
for pl = 1:length(csplate)
aux = aux + 1;
waitbar(aux/steps);
[xplot,yplot,zplot,plotSxx] = stressplot(pl,el);
surf(xplot,yplot,zplot,plotSxx);
hold on;
end
end
close(progressbar)
Question is whether it is possible to overcome this problem in any other way.
Thanks,
PN

 Accepted Answer

Please describe what you see (we don't have your data or your function.)
I have used waitbar in connection with surf without difficulty.
Have you tried
waitbar(aux/steps, progressbar);
to be sure of updating the correct bar?

3 Comments

Also, before you start the plot loop, generate a figure and generate an axes on the figure and record that handle, and supply that axes handle to surf -- otherwise there is a danger that surf() will think that the current figure is the figure of the waitbar, and it might clf() that figure internally.
Be sure to also hold(axesHandle,'on') instead of plain hold on
Ok this makes some sense... I have been able to overcome the problem provided that before I use the surf functions, the correct axes are recalled.
So my question then becomes: suppose that said axis are incluided in a gui, and I use the following instruction when I push a random button:
axes(handles.structplot1);
cla(handles.structplot1,'reset');
and then:
for el = 1:length(stelement)
for pl = 1:length(csplate)
step = step + 1;
waitbar(step/steps,progressbar);
[xplot,yplot,zplot,plotSxx] = Oplot(readmodes,pl,el,'Sxx');
axes(handles.structplot1);
surf(xplot,yplot,zplot,plotSxx);
hold(structplot1,'on')
end
end
This is obviously not yet what I want. What exactly do I need to do in order to obtain the axesHandle and how do I use it with surf and hold on instructions? I am obviously missing something here...
h = gca; i suppose. Anyway, thanks for the insight! My problem is solved.

Sign in to comment.

More Answers (2)

by the way, in the previous code, the matlab returns the following error:
Error using ==> uiwaitbar at 101
Couldn't find waitbar handles.
PN
From the help for WAITBAR (always a good place to look with any funciton!), we have this:
h = waitbar(0,'Please wait...'); % Create a waitbar.
then later:
for i=1:1000,
% computation here %
waitbar(i/1000,h) % Update the existing waitbar.
end
So you see, your update to the waitbar expects the handle returned from when you first invoked it - before the loop...

1 Comment

The doc shows that the handle is not (always) necessary.

Sign in to comment.

Categories

Find more on App Building 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!