function fout = multiwaitbar(StepAxes,TitleAxes,h_wait) %example: creation of nested waitbars, range from 0 to 1 % H = multiwaitbar([0 0 0],{'Please wait','Please wait','Please wait'}); % % OR % H = multiwaitbar([1 1 1],{'Please wait','Please wait','Please wait'}); % H = multiwaitbar([1 1 1]); % % % use of the waitbar % for i = 0:0.2:1 % for j = 0:0.2:1 % for k = 0:0.1:1 % multiwaitbar([i j k],{'Directories','Files','Items'},H); % end % end % end % delete(H) % clear('H') % %example: creation of nested waitbars, range from 1 to N % H = multiwaitbar([5 60],{'Please wait','Please wait','Please wait'}); % % OR % H = multiwaitbar([5 60], % % % use of the waitbar % for i = 1:1:5 % for j = 1:1:60 % multiwaitbar([i j],{['File ' num2str(i) '/' num2str(5)],'Section'},H); % % OR % % multiwaitbar([i j],{[],'Section'},H); % end % end % delete(H) % clear('H') % multiwaitbar (V1.0 01-2018) by http://robotica.udl.cat % inspired in multiwaitbar by Sandeep Solanki, available at: % https://es.mathworks.com/matlabcentral/fileexchange/44111-multiwaitbar % check Inputs if (nargin > 1) if ~iscell(TitleAxes) error('Message: Titles should be in a Cell array') end end NumAxes = length(StepAxes); if (nargin == 3) && ~ishandle(h_wait) error('Message: mutiwaitbar figure closed') end % Creat if (nargin < 3) % create figure set(0, 'Units', 'pixel'); screenSize = get(0,'ScreenSize'); width = screenSize(3)/3; height = NumAxes * screenSize(4)/15; pos = [screenSize(3)/2-width/2 screenSize(4)/2-height/2 width height]; h_wait = figure('Position',pos,'MenuBar','none','Numbertitle','off','Name','Please Wait..','Resize','off'); intervalo = 1/(2*NumAxes); pp = 1.0+ intervalo/4; for i = 1:NumAxes if (StepAxes(i) == 0) StepMax = 1; else StepMax = StepAxes(i); end pp = pp - 2*intervalo; axPos = [0.1 pp 0.8 1/(3*NumAxes)]; h_axes = axes('Parent',h_wait,'Box','on','Units','normalized','Position',axPos,'NextPlot','add','Tag',['A' num2str(i)]); fill([0 100 100 0],[0 0 1 1],'r','Tag',['F' num2str(i)],'UserData',StepMax); set(h_axes,'XLim',[0 100],'YLim',[0 1],'XTick',[],'YTick',[]); h_title = get(h_axes,'Title'); if (nargin == 1) set(h_title,'string','Waitbar...','Tag',['T' num2str(i)]); else set(h_title,'string',TitleAxes{i},'Tag',['T' num2str(i)]); end end drawnow; % reset time control set(h_wait,'UserData',[{0} {0}]); if (nargout > 0) fout = h_wait; end else R = zeros(1,NumAxes); % update for i = 1:NumAxes h_fill = findobj(h_wait,'Tag',['F' num2str(i)]); StepMax = get(h_fill,'UserData'); % scale R(i) = min(100*StepAxes(i)/StepMax,100); set(h_fill,'XData',[0 R(i) R(i) 0],'YData',[0 0 1 1]); h_axes = findobj(h_wait,'Tag',['A' num2str(i)]); h_title = get(h_axes,'Title'); if ~isempty(TitleAxes{i}) set(h_title,'string',TitleAxes{i}); end end % time length prediction ud = get(h_wait,'UserData'); t = ud{1}; R0 = ud{2}; if (t == 0) % first pass, no time prediction % store starting time and initial step t = clock; set(h_wait,'UserData',[{t} {R(1)}]); set(h_wait,'Name','Waitbar'); else et = etime(clock, t); es = R(1)-R0; % remaining steps if (NumAxes > 1) es = es + R0*(R(2)/100); end pendent = et / es; prediction = max([0 (100 * pendent) - et]); % disp(['et=' num2str(et) ', es=' num2str(es) ', pendent=' num2str(pendent) ', prediction=' num2str(prediction)]); % prepare message if (et > 60) aux = [sprintf('%3.1f',et/60) ' m']; else aux = [sprintf('%2.0f',et) ' s']; end if (prediction > 60) aux = [aux ' / ' sprintf('%3.1f',prediction/60) ' m left']; else aux = [aux ' / ' sprintf('%2.0f',prediction) ' s left']; end set(h_wait,'Name',aux); end drawnow; end