how to update progress gauge based on analyze progress in App designer GUI ?

11 Ansichten (letzte 30 Tage)
LO
LO am 4 Jul. 2020
Beantwortet: Mehdi Ansarey am 11 Okt. 2023
I am trying to use a gui to go through some data and analyze segments of them.
I am able to select different segments using a spinner which value is then used to "cut" segments from my data: if spinner value =1 then take the first 100 points, if equals 2 the second 100, etc. each segment is one minute.
at the end of each minute analysis, I made a save button which is suppose to store some data back in the workspace as variables. In addition to that (which I have not yet implemented), I would like this button to calculate how much of my analysis is left by taking the spinner value, store it somewhere and - based on the total amount of segments set in a text box somewhere else - it should give out a % of progress onto a "gauge bar". I have already tried to create a "storing" variable in the app but it does not work: there is no place where I could initialize the variable (creating an empty array for instance) to which then I could append values... so I thought maybe I could use the work space for this and append spinner values to a "storing variable" and then read the storing variable to calculate a progress percentage. however it seems I can 't really create new vars in the workspace (I know the assignin function but somehow I get an error when I tried to create a new var from the app).
this is my code
function savedataButtonPushed(app, event)
value = app.selectminuteSpinner.Value; % reads value from the spinner
REC = app.RECdurationminTextArea.Value; % read value from a text box in which the total duration of the analysis (i.e. the tot number of segments to analyze) is set
completion = (str2double(value)/str2double(REC))*100; % up to this line should work but should give the wrong % since it reads only one value and does not consider the history
% however it seems I can't read the value of completion and apply it directly to the gauge: is not read as a number, even though I am converting it to double
assignin('base',valuew,app.selectminuteSpinner.Value); % here is my attempt to save values in the workspace, which fails
assignin('base',RECw,REC); % same as above
app.Gauge.Value = str2double(completion); % this does not work because somehow the format of 'completion' is wrong
end

Antworten (1)

Mehdi Ansarey
Mehdi Ansarey am 11 Okt. 2023
The Rule of thumb for implementing progress bar is to hanfle below tasks:
1) Initialize
2) Progress Strategy
3) Finalize
The Initializing, is where your work start. if you define a property field in your app class, Initialize it to zero or whatsover init value. If you use an independant matlab function, initialize persistent var. The 2nd task is when each step of progress you want echo to user, and when done, you should delete the progress bar.
You can implement all three task in single function like below:
function ProgressBar(V, ProgBarHandle, EndFlag)
persistent Value, hProgBar
if isempty(V)
Value= 0;
hProgBar= waitbar(0, 'Please wait...');
end
Value= V;
% Show Progress Bar, Or Update Some Control In App By ProgBarHandle
waitbar(Value, hProgBar, 'In Progress');
if nargin == 3
% Clear Progress Bar
delete(hProgBar)
end
end

Kategorien

Mehr zu Interactive Control and Callbacks 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!

Translated by