0001 function progress_bar(action,progress,title)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 if isequal(nargin,0),
0033 action = 'init';
0034 end
0035
0036 action = lower(action);
0037
0038
0039
0040 if strcmp(action,'init'),
0041
0042 tim = clock;
0043 timestr = sprintf(' Began %02.0f:%02.0f:%02.0f',tim(4),tim(5),tim(6));
0044
0045 if exist('title','var'),
0046 if ~isempty(title),
0047 name = strcat(sprintf('%s -',title),timestr);
0048 else
0049 name = strcat('Progress -',timestr);
0050 end
0051 else
0052 name = strcat('Progress -',timestr);
0053 end
0054
0055 fg = figure('MenuBar','none',...
0056 'NumberTitle','off',...
0057 'Name',name,...
0058 'Tag','ProgressBar',...
0059 'BackingStore','off',...
0060 'Pointer','watch',...
0061 'Position',[1 1 300 75]);
0062 movegui(fg,'center');
0063 ax = axes('Position',[0.1 0.25 0.8 0.4],...
0064 'YTick',[],...
0065 'Xlim', [0 1],'Ylim',[0 1],...
0066 'Box','on',...
0067 'FontSize',8,...
0068 'Tag','ProgressBarAxis',...
0069 'Parent',fg);
0070
0071 xlab = get(ax,'xticklabel');
0072 xlab = str2num(xlab) * 100;
0073 xlab = num2str(xlab);
0074 set(ax,'xticklabel',xlab)
0075
0076 if exist('progress','var'),
0077 if ~isempty(progress), setpb(fg,progress);
0078 else
0079 progress = 0;
0080 setpb(fg,progress);
0081 end
0082 else
0083 progress = 0;
0084 setpb(fg,progress);
0085 end
0086
0087 drawnow;
0088
0089
0090
0091 elseif strcmp(action,'set'),
0092
0093 fg = findobj('Tag','ProgressBar');
0094
0095 if ~isempty(fg), setpb(fg,progress); end;
0096
0097
0098
0099 elseif strcmp(action,'clear'),
0100 fg = findobj('Tag','ProgressBar');
0101 if ~isempty(fg), close(fg); end;
0102 end;
0103
0104 return
0105
0106
0107
0108 function setpb(fig,progress)
0109
0110 pbaxis = findobj(fig,'Tag','ProgressBarAxis');
0111
0112 if ~isempty(pbaxis),
0113
0114 vert = [0 0; progress 0; progress 1; 0 1];
0115 face = [1 2 3 4];
0116
0117 pbpatch = findobj(fig,'Tag','ProgressBarPatch');
0118
0119 if ~isempty(pbpatch),
0120 set(pbpatch,'Vertices',vert);
0121 else
0122 pbpatch = patch('Faces',face,'Vertices',vert,'FaceColor','r',...
0123 'Tag','ProgressBarPatch',...
0124 'EraseMode','none',...
0125 'Parent',pbaxis);
0126 end
0127
0128 title = get(pbaxis,'Title');
0129 set(title,'string',sprintf('%5.1f%% Complete',100*progress),'EraseMode','xor');
0130
0131 drawnow;
0132
0133 figure(fig);
0134 end;
0135 return