How to steer uiprogressdlg from external function

Hello
I am building an App wit appdesigner in which a rather complex function is called. The function is at the moment not within the app. Due to its complexity, it is a standalone function file. First of all, its 1500 lines of code would make the app code extremely long. Furthermore, working within the normal matlab interface enables me much more do to optimisations and tests on the function. Within the app it is much more difficult to look at intermediate values etc.
Within the function, I use the waitbar a lot to show progress through all the different calculation steps (as calculations can take multiple hours). Now for the app, I assume it is best to use uiprogressdlg for that purpose. In the end, this app must be deployed standalone to non-Matlab users.
However, I don't seem able to steer the uiprogressdlg from the external function. Is there a way to do this? Or is my only option to integrate the function fully within the app?

 Respuesta aceptada

Jiri Hajek
Jiri Hajek el 10 de Nov. de 2022
Hi, I believe you could use the function setappdata, which allows you to change global variables in your app from an external function:
setappdata(obj,name,val)

5 comentarios

I tried but this function seems to be built towards figures and not UIFigures like the AppDesigner is using... When I start with defining the object as "uifigure", it just opens a new uifigure, I don't find how to refer to the existing UIFigure.
Please try again, I'm using this for quite a long time, in AppDesigner. You have to take into account the following>
  • The uiprogressdlg displays the progress using a Value, like this:
d = uiprogressdlg(fig,Name,Value)
  • The Value needs to be defines as a global property in your app (e.g. "MyProgressValue".
  • Inside the external function, you will set the value of the "MyProgressValue". Since it will be already used by the progress dialog, its graphics will be updated.
  • You will not call any new or existing uifigure. The app has its own handle, which you need to pass to the external function ("MyApp"). Your parameter will be then changed using
setappdata(MyApp, MyProgressValue, yournewvalue)
Hi Jiro, thanks for taking the time to explain this.
I think I get how I have to do it however there is still one thing that doesn't work out and that is passing the app handle
At the moment, I call the external function from within the app with
myApp()
...
myFunction(value1, value2, app)
...
end
and I have listed 'progressValue' and 'progressMessage' as public properties.
Then in the function itself, I inserted the following codes as per your explanation:
myFunction(var1, var2, myApp)
...
newProgressValue = 0.1;
newProgressMessage = 'Some text to display.';
setappdata(myApp, 'progressValue', newProgressValue);
setappdata(myApp, 'progressMessage', newProgressMessage);
...
end
but I get the error message:
error: Input was not a valid graphics object
How do I pass the app correctly in the function handle / read the app correctly in the function?
Thanks a lot!
Hi Simon, I'm afraid I confused two things yesterday. In fact, you have two alternative possiblities, which I mixed up together - sorry for that. Using the handle of the progress dialog you simply change them same way as if you were inside your app. You may safely forget about the setappdata function, it is unnecessary in your case.
In your app, create a hadle of the progres dialog window, which just needs to be defined as a global property:
properties
MyProgressDlg % handle of your progress dialog
end
...
...
...
MyApp.MyProgressDlg = uiprogressdlg(app, .......);
In your external function, you can directly access the properties of the dialog window:
myFunction(var1, var2, myApp)
...
newProgressValue = 0.1;
newProgressMessage = 'Some text to display.';
MyApp.MyProgressDlg.Value = newProgressValue;
MyApp.MyProgressDlg.Message = newProgressMessage;
...
end
Hope this helps.
This works perfectly! Thanks for your elaborate example, now I'm able to make all the necessary connections between my app and my external function.
All the best,
Simon

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 10 de Nov. de 2022

Comentada:

el 14 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by