필터 지우기
필터 지우기

How to update uiprogressdlg inside a separate .m function?

조회 수: 12 (최근 30일)
Levi Blake
Levi Blake 2022년 2월 15일
답변: Nivedita 2023년 12월 4일
I have a function called Main(x,y,z,etc.) that contains all of the calculations for my program and needs to be a separate .m file because it is called directly by multiple services. One of the services that calls the function is a UI that I built in App Designer in which I use the uiprogressdlg() command to display an 'indeterminant' progress bar to tell the user that the program is working. Recently I've made changes to the code that can extend the runtime to a couple of minutes in some cases, so I'd like to allow the progress bar to actually show the current progress so that users know that it's not locked up. Is there a way to update uiprogressdlg() within Main() to achieve this?
  댓글 수: 1
Benjamin Thompson
Benjamin Thompson 2022년 2월 15일
There are always global variables but you probably want something more elegant than that. Can you post some sample code

댓글을 달려면 로그인하십시오.

답변 (1개)

Nivedita
Nivedita 2023년 12월 4일
Hello Levi,
You can update the "uiprogressdlg" from within your "Main" function to show the progress of your calculations. To achieve this, you can use the "Dialog" object returned by the "uiprogressdlg" function and update its properties to reflect the progress.
Here's an example of how you can achieve this:
function Main(x, y, z, etc.)
% Initialize progress dialog
dlg = uiprogressdlg('Title', 'Calculating', 'Indeterminate', 'on');
% Perform your calculations
for i = 1:totalIterations % Replace totalIterations with the actual number of iterations
% Your calculation code here
% Update progress dialog
dlg.Value = i / totalIterations; % Update the progress value
drawnow; % Force the graphics to update
end
% Close progress dialog
close(dlg);
end
  • Within the calculation loop, the "Value" property of the "dlg' object is updated to reflect the progress of the calculations.
  • The "drawnow" function is called to force the graphics to update and show the progress in the dialog.
  • After the calculations are completed, the "close" function is used to close the progress dialog.
By updating the "Value" property of the "uiprogressdlg" object within your "Main" function, you can show the progress of the calculations to the user, allowing them to know that the program is still working.
For more information on the "uiprogressdlg" and "drawnow" functions, please refer to the following documentation links:
I hope it helps!
Regards,
Nivedita.

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by