progress bar in app design (GUI)
Show older comments
Hi!
I need to create a progress bar like the following bar with the APP DESIGN:

% Button pushed function: ProcessDataButton
function ProcessDataButtonPushed(app, event)
% Change button name to "Processing"
app.ProcessDataButton.Text = 'Processing...';
% Put text on top of icon
app.ProcessDataButton.IconAlignment = 'bottom';
% Create waitbar with same color as button
wbar = permute(repmat(app.ProcessDataButton.BackgroundColor,15,1,200),[1,3,2]);
% Black frame around waitbar
wbar([1,end],:,:) = 0;
wbar(:,[1,end],:) = 0;
% Load the empty waitbar to the button
app.ProcessDataButton.Icon = wbar;
% Loop through something and update waitbar
n = 10;
for i = 1:n
% Update image data (royalblue)
currentProg = min(round((size(wbar,2)-2)*(i/n)),size(wbar,2)-2);
app.ProcessDataButton.Icon(2:end-1, 2:currentProg+1, 1) = 0.25391;
app.ProcessDataButton.Icon(2:end-1, 2:currentProg+1, 2) = 0.41016;
app.ProcessDataButton.Icon(2:end-1, 2:currentProg+1, 3) = 0.87891;
% Pause to slow down animation
pause(.3)
end
% remove waitbar
app.ProcessDataButton.Icon = '';
% Change button name
app.ProcessDataButton.Text = 'Process Data';
end
I need the progress bar to update AFTER calling my function, so I changed it into something like that:
% Button pushed function: ProcessDataButton
function ProcessDataButtonPushed(app, event)
% Change button name to "Processing"
app.ProcessDataButton.Text = 'Processing...';
% Put text on top of icon
app.ProcessDataButton.IconAlignment = 'bottom';
% Create waitbar with same color as button
wbar = permute(repmat(app.ProcessDataButton.BackgroundColor,15,1,200),[1,3,2]);
% Black frame around waitbar
wbar([1,end],:,:) = 0;
wbar(:,[1,end],:) = 0;
% Load the empty waitbar to the button
app.ProcessDataButton.Icon = wbar;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Loop through something and update waitbar
my_function(do things...)
<events?>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% remove waitbar
app.ProcessDataButton.Icon = '';
% Change button name
app.ProcessDataButton.Text = 'Process Data';
end
My problem: I don't know how to keep trace of my updates. Do I need to create an event? I followed this guide: Define Custom Event Data - MATLAB & Simulink - MathWorks Italia, but I did not manage to solve my problem: I need intermediate output before the end of the function to trace my advancements (hope to explain myself, my technical language is poor in this field). Is my path ok or not?
Do you have suggestions? Thank you
5 Comments
Adam Danz
on 19 Feb 2021
@Veronica Taurino it depends on what's controlling your updates. Are the updates done in a loop? Are the updates done in sections of code?
Also, are the updates done in the app file or outside of the app?
Veronica Taurino
on 19 Feb 2021
Edited: Veronica Taurino
on 19 Feb 2021
Adam Danz
on 22 Feb 2021
See the 3 easy steps below.
Gareth
on 7 May 2021
Would be nice if this shipped with App Designer, it is a common thing for User Interfaces.
Adam Danz
on 7 May 2021
Accepted Answer
More Answers (0)
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!