waitbars in R2015b

5 visualizaciones (últimos 30 días)
Oliver Chikumbo
Oliver Chikumbo el 11 de Oct. de 2015
Comentada: Oliver Chikumbo el 14 de Mzo. de 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 comentario
Oliver Chikumbo
Oliver Chikumbo el 14 de Mzo. de 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+

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 12 de Oct. de 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 comentarios
Oliver Chikumbo
Oliver Chikumbo el 12 de Oct. de 2015
Editada: Oliver Chikumbo el 12 de Oct. de 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 el 12 de Oct. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 11 de Oct. de 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 comentarios
Oliver Chikumbo
Oliver Chikumbo el 11 de Oct. de 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 el 12 de Oct. de 2015
I do not have that version to check with.

Iniciar sesión para comentar.

Categorías

Más información sobre App Building en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by