App Designer - Edit grayed out code

Hi,
I need to edit the grayed out code in the code view of my MatLab app to write initialization code.
I am building a MatLab app frontend for a backend which already exists. This backend has an object-oriented design and needs to run initialization code to read data and populate the data storage objects. How can I call the initialization code in the constructor of the app, or somewhere at the begininning of the program, once?
Thanks for your help.

답변 (3개)

B Verhaar
B Verhaar 2021년 3월 23일

1 개 추천

I think this is what you need:
Startup Tasks and Input Arguments in App Designer

댓글 수: 1

Ajith Gunatilaka
Ajith Gunatilaka 2021년 9월 16일
Thank you. This helped me out.
I wanted to set the latex interpreter for Ylable before displaying a GUI with a graph. Unlike for edit box labels, I could not do this in the component browser. But now I was able to add it as a startup task.
Thanks for this useful tip.

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

Luna
Luna 2019년 1월 22일
편집: Luna 2019년 1월 22일

0 개 추천

Copy the whole code app designer produced and past it another blank .m file and save it.
Then you can edit the properties, constructor method and run it easily.
Maybe there is another easy way to do it.
I generally prefer to code my own GUI instead of app designer.

댓글 수: 5

Odilon Lemieux
Odilon Lemieux 2019년 1월 22일
편집: Odilon Lemieux 2019년 1월 23일
I will give that a try, thanks.
Edit: This approach did not work. I changed the code as a .m file then saved it again as a .mlapp file. When I tried to run it again or open it in the matlab app editor it gave the error saying error loading 'filename'.
Luna
Luna 2019년 1월 24일
Share the code then we see what's wrong.
Tom Paraschuk
Tom Paraschuk 2019년 1월 24일
This approach won't work.
A .mlapp file is made of a .zip file with several different types of files inside. They can be accessed using the method (or hack) at this link: http://undocumentedmatlab.com/blog/appdesigner-mlapp-file-format.
Unfortunately, the .mat file in the location appdesigner/appModel.mat referred to in step 3 of the link is encrypted. So this method will not work unless someone knows a way to decrypt that file.
Tom Paraschuk
Tom Paraschuk 2019년 1월 24일
I have a workaround: the startup function for a MatLab app, described at https://www.mathworks.com/help/matlab/creating_guis/app-designer-startup-function.html.
That being said, the app designer software's locking you out of editing the code in any way is a very bad feature.
Luna
Luna 2019년 1월 28일
편집: Luna 2019년 1월 28일
I think you did different thing than what I said above. Create your application in appdesigner, put some buttons, gui elements, etc. Go to code view, and copy whole code.
Than open a new blank .m file on Matlab, past it to there and save new app.m. This must be a classdef file (an object definition with its methods and properties)
Now you can both edit and when you click run your app(GUI) will be executed.
Be careful about editing, if you are not familiar with object oriented programming.
Note: As I see you saved .mlapp file and this is not what I explained.

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

Parisa Zomorodian
Parisa Zomorodian 2020년 12월 7일

0 개 추천

Your solution didnt work for me as well.
You can click on the arrow under "save" button and choose "export to .m file...". You can edit the mfile afterward.

댓글 수: 1

Luna
Luna 2021년 3월 23일
편집: Luna 2021년 3월 23일
What was the error? This method works perfectly in my computer.
You should know the structure of the code and which functions run first. As I said you should not be saving a mlapp file. You should save a .m file and you will run this .m file. If you have another depended .m files put them on the same folder and check where you call them in main .m file.

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

카테고리

도움말 센터File Exchange에서 Software Development Tools에 대해 자세히 알아보기

제품

릴리스

R2018b

질문:

2019년 1월 22일

댓글:

2021년 9월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by