MATLAB: Waitbars in R2015b

r2015bwaitbars

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.

Best Answer

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.