waitbars in R2015b

5 views (last 30 days)
Oliver Chikumbo
Oliver Chikumbo on 11 Oct 2015
Commented: Oliver Chikumbo on 14 Mar 2016
I have a GUIDE figure with a waitbar that runs inside the main figure under R2014a, but in R2015b here is what is happening:
% waitbar specification
f1 = findobj('Tag','MonteFig');
wb = waitbar(0,'Simulating ...');
c = get(wb,'Children'); % make the waitbar part of the current figure
set(c,'Parent',f1); % set the position of the waitbar on current figure
% Simulation
t = 2; g(1) = 0; % initialization
for i = 1:K,
waitbar(i/K,wb); ...
"Simulating ..." appears in the main figure, but the waitbar opens its own figure and runs without any errors. Not sure how to fix it and cannot see on my search on the internet what it is I could do different to make it work like it does on R2014a.
  1 Comment
Oliver Chikumbo
Oliver Chikumbo on 14 Mar 2016
Nothing was wrong with my code and all I needed to do was to change the first statement to the current figure: f1 = gcf;
... and it fixed the problem. Under R2014a I could just as easily identify the gcf with with its Tag but for some reason it will not work in R2014b+

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 12 Oct 2015
Here's the function I use to display a progress bar on my main GUI figure window:
%--------------------------------------------------------------------
% Displays a progress bar on the figure at the specified location.
function h = DisplayProgressBar(varargin)
%DisplayProgressBar: A progress bar that can be embedded in a GUI figure.
% Syntax and sample calling:
% progressBarPosition = [.376 .414 .198 .052]; % Position of progress bar in normalized units.
% handleToProgressBar = DisplayProgressBar(progressBarPosition);
% for k = 1:100
% percentageDone = k / 100;
% DisplayProgressBar(handleToProgressBar, percentageDone)
% end
% % Delete the progress bar. Make it disappear.
% delete(handleToProgressBar);
% Written by Doug Schwarz, 11 December 2008
try
if ishandle(varargin{1})
ax = varargin{1};
value = varargin{2};
p = get(ax,'Child');
x = get(p,'XData');
x(3:4) = value;
set(p,'XData',x)
return
end
pos = varargin{1};
backgroundColor = [249, 158, 0] / 255; % Orange.
foregroundColor = [0 .5 0]; % Dark Green
h = axes('Units','normalized',...
'Position',pos,...
'XLim',[0 1],'YLim',[0 1],...
'XTick',[],'YTick',[],...
'Color', backgroundColor,...
'XColor', backgroundColor,'YColor', backgroundColor);
patch([0 0 0 0], [0 1 1 0], foregroundColor,...
'Parent', h,...
'EdgeColor', 'none');
% set(h, 'units', 'normalized');
catch ME
message = sprintf('Error in DisplayProgressBar():\n%s', ME.message);
WarnUser(message);
end
return; % from DisplayProgressBar()
I don't think I've tried it with R2015b yet though.
  2 Comments
Oliver Chikumbo
Oliver Chikumbo on 12 Oct 2015
Edited: Oliver Chikumbo on 12 Oct 2015
I saw this code somewhere on my Internet searches, which a little different from a waitbar, and folks are having problems running it in R2014b. This implies that I would have issues too (since the majors on graphics were made from R2014b) and so I have had no drive to play around with it. But thanks anyway. If you are thinking of upgrading to R2015b at some stage remember that these are some of the issues you will have to deal with to get your code running smoothly again.
Image Analyst
Image Analyst on 12 Oct 2015
I have R2015b already but I don't think I've run the m-file that uses that code. If I remember, tomorrow, I'll try to run it and let you know how it goes. I liked this version better since it shows up right on my GUI and not as a popup window that can disappear if the user happened to click on their GUI and bring the GUI to the front, thus obscuring the popup waitbar.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 11 Oct 2015
The handle visibility of the children might be 'off' or 'callback' so you might not see them when you get() the children of the waitbar figure.
  2 Comments
Oliver Chikumbo
Oliver Chikumbo on 11 Oct 2015
Thanks Walter ... the HandleVisibility was indeed defaulted to 'callback' which I changed to 'on' [set(wb, 'HandleVisibility', 'on')] and now c [c = get(wb,'Children')] shows an output. However, the problem still remains and that is "Simulating ..." shows on the main figure, and the waitbar shows up as a different figure.
Walter Roberson
Walter Roberson on 12 Oct 2015
I do not have that version to check with.

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!