progressbar() issue, fails after one iteration
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Douglas Anderson
am 29 Apr. 2022
Bearbeitet: Walter Roberson
am 30 Apr. 2022
Hello!
I downloaded and ran progressbar() today to replace waitbar() with the following code:
FILE_LENGTH = 5000; % Assume that 5,000 is large enough
complete_waveforms = zeros(FILE_LENGTH,4,num_selections);
sample_interval = zeros(1,num_selections);
%max_waveforms = zeros(4,num_selections);
progressbar(1);
for n = 1:num_selections
% waitbar(n/num_selections,'Reading files');
progress_counter = n/num_selections;
progressbar(progress_counter,'Reading files');
[~,~, fExt] = fileparts(file_names(n,:));
switch fExt
case '.TXA'
% A TXA file
[~, ~, this_waveform, ~, ~] = read_msp_txa_file_v1(path_to_file, file_names(n,:));
% Component order in waveforms is: Time T V L Mic
sample_interval(n) = this_waveform(2,1) - this_waveform(1,1);
complete_waveforms(:,:,n) = this_waveform(:,2:5);
case '.txt'
% A txt file
[~, ~, this_waveform, ~, ~] = read_geosonics_txt_file_v3(path_to_file, file_names(n,:));
% Component order in waveforms is: Time L T V Mic
sample_interval(n) = this_waveform(2,1) - this_waveform(1,1);
complete_waveforms(:,:,n) = [circshift(this_waveform(:,2:4),2,2) this_waveform(:,5)];
otherwise % Under all circumstances SWITCH gets an OTHERWISE!
error('Unexpected file extension: %s', fExt);
end
end
num_selections is predefined. When I run with a debug on the "progress_counter =..." line and n = 1, it progresses, but when I step to n=2, it fails on progressbar(...) with the following output:
Error using matlab.graphics.primitive.Patch/set
Input XData value must be numeric.
Error in progressbar (line 270)
set(progdata(ndx).progpatch, 'XData', ...
Error in va2_46>go_button_Callback (line 427)
progressbar(progress_counter,'Reading files');
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in va2_46 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)va2_46('go_button_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
n just steps normally and progress_counter is just a fractional number. This worked fine with waitbar(), but just wasn't as pretty, was kind of jerky, and left many windows around.
Any thoughts on this issue, or how to clean up after waitbar()?
Thanks
Doug
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 29 Apr. 2022
Bearbeitet: Walter Roberson
am 30 Apr. 2022
Each parameter to progressbar() corresponds to a different bar. You are creating two bars. You are updating two bars. But when you update bars you can update the label by passing in a character vector, or you can update the fraction by passing in a numeric value.
The examples in the documentation do not show any instances of updating a numeric value for one bar but updating a label for another. It shows updating all labels, and it shows updating all fractions, and it shows skipping by passing in empty in the position.
I think you converted waitbar() with an initial value and a label into a single progressbar() call, not noticing that you were creating two bars instead. Call progressbar() once with the one label and then in the loop call with a single numeric update.
2 Kommentare
Walter Roberson
am 29 Apr. 2022
Your difficulty with waitbar() is that when you call waitbar() without passing in a reference to a waitbar, it can create an additional waitbar. And you do not delete the waitbar after.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dialog Boxes finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!