How to show that calculation is going in MATLAB App

26 ビュー (過去 30 日間)
Dhananjay Singh
Dhananjay Singh 2021 年 10 月 12 日
回答済み: dpb 2021 年 10 月 12 日
A rough app I have recreated.When the user clicks "Calculate", I want to show that calculations are happening like a progress bar or "Calculate" Button changes to "Calculating" and after calculations are done revert back to "Calculate".
Code for app is:
a = app.Number1EditField.Value;
b = app.Number2EditField.Value;
x = 10*rand(1,1);
eqn = 12- (a+b+x);
while eqn ~= 0
x = x + 0.0001;
end
app.AnswerEditField.Value = x;
% P.S I know here the answer won't come.

採用された回答

Kevin Holly
Kevin Holly 2021 年 10 月 12 日
編集済み: Kevin Holly 2021 年 10 月 12 日
You can create a status text in the App Designer by dragging "Label" onto your app in Design View. You can edit the font, alignment, and background color to fit your needs. You can uncheck the Visible check box. When calculation are being performed, you can add this to the callback that triggers the calculation:
set(app.Label, 'Visible', 'on'); drawnow;
Once it is done, you can add:
set(app.Label, 'Visible', 'off'); drawnow;
Note, you can rename your components by double clicking its name in the Component Browser. So you can change the name from app.Label to app.statusText, if you so desire.

その他の回答 (2 件)

Steven Lord
Steven Lord 2021 年 10 月 12 日
You could use a uiprogressdlg dialog.

dpb
dpb 2021 年 10 月 12 日
An outline of the progress dialog implementation I used for one app...
% Button pushed function: UpdateButton
function UpdateButtonPushed(app, event)
% disable the pushbutton so can't queue more events; change text to show we're busy
app.UpdateButton.Enable='off'; app.UpdateButton.Text="Working"; app.UpdateButton.FontColor='r';
app.QuitButton.Enable='off';
drawnow nocallbacks % have to refresh screen to be sure updates a shown immediately
%...a whole bunch of error-checking code in here elided for brevity...
% insert a progress dialog for grins...
h=uiprogressdlg(app.RestrictedFundsAwardsWorkbookUpdateToolUIFigure, ...
"Title",'Please Standby...',"Message",'Reading Billing',"Indeterminate","on");
% the actual call to the function that does all the work...
[tBill,tPay]=readBilling(app.billQualFile,app.billSheet,app.billUpdate);
% the first phase is completed; change the progress message to reflect
h.Message='Writing Awards';
writeAwards(tBill,tPay,app.year,app.semester,app.awardQualFile,app.awardSheet);
% all done; change the progress message to reflect; pause long enough
% user can read message (if they're looking :)
h.Message='Update Complete';
pause(0.5)
close(h)
% now reenable the buttons and replace original label...
app.UpdateButton.Text="Update"; app.UpdateButton.FontColor='k'; app.UpdateButton.Enable='on';
app.QuitButton.Enable='on';
drawnow
end
Above seems to work like a champ...

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by