How do I convert a script into an app?

Hello,
I created an app using app designer to get inputs and run a function. I was frusturated by the inability to edit the component initializations, which were grayed out. So I saved my .mlapp file to a .m file, and everything seemed to work. The trouble is, I can't convert my script back to an app. When I change the file extension to .mlapp and try to open it in App Designer, it just says error loading 'myapp.mlapp'. I ultimately want an executable somebody with no coding knowledge can click on and run. Can anyone help?

10 Comments

You can try to compile directly with mcc but I wouldn't hold my breath if you've munged on the startup code created by App Designer...
Out of curiosity, what couldn't you set as initial properties on the controls via the GUI app designer interface or include in the startup routine called immediately after object creation?

I wanted to give my date picker field an initial value(ie, today’s date) when the component was initialized. Wouldn’t let me edit any of that stuff.

How many controls do you have on the figure? Can you just rebuild the app in AppDesigner and then upload it so we can fix it?
"I wanted to give my date picker field an initial value(ie, today’s date)...
Set the value in the startup code...that's what it's there for. The main function for an app designer app structurally is
function app = YOUR_APP_FILE
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
This all happens before the user gets access to the controls to begin manual navigation of the app so it's transparent to the user.
Put your dynamic component initialization stuff in the startupFcn which is user code. At the App level, the Callabacks window lets you assign the name of your choice as the startup function which you then can edit to your heart's content...I attached a small screen snip of the area in Code View of a brand new app even before any components are added.
dpb
dpb on 27 Feb 2025
Edited: dpb on 27 Feb 2025
"Can you just rebuild the app in AppDesigner..."
I would presume the original .mlapp file must still be around? Just reload it and make the dynamic component settngs in the user startup function instead.
Yes, @dpb is right. If your initialization is not some constant value then you cannot set it in AppDesigner's properties window because what ever you set there will be the same every time you start your app. If you want it to change, like to set the date picker to today's date, or things like that, then you'll have to get or create the current value in your startup function and then apply it (set the property) there in the startup function instead of in the property window.
It wouldn't be a bad idea to have some more flexibility like "Today's Date" as an initialization choice for DatePicker component, but it's essentially trivial to include in the startup function so I think there are more important things to work on first...
Ok, thanks for the info about the startup function; that wasn't included from the blank app template in app designer so I'll have to add it. Sadly, my original mlapp file is gone/bugged so I'll have to recreate it. I only had 6 components and I have all their info so it shouldn't be hard.
dpb
dpb on 27 Feb 2025
Edited: dpb on 27 Feb 2025
"...my original mlapp file is gone..."
Sorry to hear that; I was hoping you had done a "SaveAs" and not just renamed the existing .mlapp file...glad to hear it wasn't that large so as to be able to recreate relatively painlessly.
Yes, adding a "callback" startup function is like adding any other component in App Designer; the code template isn't there until it is added. I hadn't really thought about that in ages as I've not built a brand new app from total scratch in "like since forever" as I've just created derivatives of an existing app. It does seem ubiquitous enough that Mathworks might consider an enhancement request to have that one user function be created automagically but with being only one click and symmetric with everything else, it's not a likely one to make the cut I'd reckon.

Sign in to comment.

Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products

Release

R2024a

Asked:

Ben
on 26 Feb 2025

Edited:

dpb
on 27 Feb 2025

Community Treasure Hunt

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

Start Hunting!