6060% 
6161% 
6262%  created 2023. 07. 14.
63- %  edited 2023. 07. 19 .
63+ %  edited 2023. 07. 30 .
6464%  author Cho HyunGwang
6565%  
6666%  https://github.com/elgar328/matlab-code-examples/tree/main/tools/ProgressBar
106106 %  ------------------------ Properties for GUI -------------------------
107107 properties  (Access  =  private , Transient )
108108 bar_ratio  =  0 ;
109+  prev_count_time 
109110 end 
110111 properties  (SetAccess  =  immutable , Hidden  =  true , Transient )
111112 fig_handle 
158159 end 
159160 %  ---------------------------- Counter ----------------------------
160161 function  count(obj )
161-  if  obj .no_parallel_toolbox  ||  isempty(getCurrentJob )
162+  %  The || operator was not used intentionally.
163+  %  Short circuit does not work normally under certain conditions.
164+  if  obj .no_parallel_toolbox 
165+  obj .localIncrement(); %  Serial processing
166+  elseif  isempty(getCurrentJob )
162167 obj .localIncrement(); %  Serial processing
163168 else 
164169 send(obj .Queue , true ); %  Parallel processing
@@ -179,11 +184,9 @@ function delete(obj)
179184 methods  (Access  =  private )
180185 %  ------------------------- localIncrement ------------------------
181186 function  localIncrement(obj )
182-  persistent  prev_count_time 
183- 
184187 if  isempty(obj .start_time ) %  at first count
185188 obj.start_time =  datetime();
186-  prev_count_time =  datetime();
189+  obj. prev_count_time =  datetime();
187190 if  strcmp(obj .ui_type ,' cli'  )
188191 update_cli(" "  , true , true );
189192 end 
@@ -192,11 +195,11 @@ function localIncrement(obj)
192195 obj.counter =  1  +  obj .counter ;
193196 obj.ratio =  obj .counter / obj .N ;
194197
195-  if  (seconds(datetime()-prev_count_time ) <  obj .frame_interval_limit ) ...
198+  if  (seconds(datetime()-obj . prev_count_time ) <  obj .frame_interval_limit ) ...
196199 &&  (obj .counter  ~=  obj .N )
197200 return 
198201 end 
199-  prev_count_time =  datetime();
202+  obj. prev_count_time =  datetime();
200203
201204 switch  obj .ui_type 
202205 case  ' cli' 
0 commit comments