progressbar() issue, fails after one iteration

4 ビュー (過去 30 日間)
Douglas Anderson
Douglas Anderson 2022 年 4 月 29 日
編集済み: Walter Roberson 2022 年 4 月 30 日
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

採用された回答

Walter Roberson
Walter Roberson 2022 年 4 月 29 日
編集済み: Walter Roberson 2022 年 4 月 30 日
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 件のコメント
Walter Roberson
Walter Roberson 2022 年 4 月 29 日
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.
Douglas Anderson
Douglas Anderson 2022 年 4 月 30 日
Thank you very much Walter, for this and your other help. I was interviewed by Loren Shure of MathWorks just before she retired, and we discussed the tireless work that people do in the Community. Your work, in particular, stands out, and is really appreciated. Thank you!
And as you indicated in your answer, yes, I just used the same format for progressbar() as I used for waitbar(). It's working fine now! As my high school biology teacher said, "When all else fails, follow the directions".
Doug

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDialog Boxes についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by