Launch a matlab script when push button app designer Matlab

47 ビュー (過去 30 日間)
Lucas S
Lucas S 2019 年 4 月 12 日
編集済み: Raed Wasseghi 2020 年 10 月 10 日
Hello !
I have already created a button that allow user to browse a file and a TextArea that display the File Path.
function Browse(app, event)
[FileName,FilePath ]= uigetfile();
ExPath = fullfile(FilePath, FileName);
app.FileTextArea.Value = ExPath;
end
And now i would like to create another button that launch a matlab script (function) with the file in parameter I don't know how to do that, first time i use app designer.
Thanks for helping !
Edit : i tried this :
function Launch(app, event)
Path = string(app.FileTextArea.Value);
testLectureXML(Path);
end
testLectureXML is my matlab script.
But it returned me :
Undefined function 'Launch' for input arguments of type 'Apptest'.
  3 件のコメント
Lucas S
Lucas S 2020 年 4 月 30 日
Hello !
Yes. I put an Edit Text next to the Browse button to display the name of the file.
And then in the callbackFunction of the button ("play" or "run" in don't know what is your button app) you just create a variable which contains the value of the EditText and then you just call your script with the variable inside.
function RunButtonPushed(app, event)
file = app.EditText.Value;
scriptName(file);
end
Raed Wasseghi
Raed Wasseghi 2020 年 10 月 10 日
編集済み: Raed Wasseghi 2020 年 10 月 10 日
hi!
I am having the same problem but the solution you have posted somehow doesnt work for me.
In my app designer there's no "edittext" but rather an "edit field (text)" and "editfield (nummeric)" and if I execute this code:
function RunButtonPushed(app, event)
file = app.Editfield.Value;
scriptName(file);
end
and i get this error: Attempt to execute SCRIPT Test_Zeilentausch_qualitaet as a function: [path]
But I can't write "app.editfield.string" it doesnt exist.
Do you have any solution on this? and do you know if the values appear in the workspace once I run the script?

サインインしてコメントする。

回答 (1 件)

Adam Danz
Adam Danz 2019 年 4 月 12 日
編集済み: Adam Danz 2019 年 4 月 12 日
  1. Open your project in app designer : https://www.mathworks.com/help/matlab/ref/appdesigner.html
  2. Add the button: https://www.mathworks.com/help/matlab/creating_guis/choose-components-for-your-app-designer-app.html
  3. Add a ButtonPushedFcn callback function to the button: https://www.mathworks.com/help/matlab/creating_guis/write-callbacks-for-gui-in-app-designer.html and https://www.mathworks.com/help/matlab/ref/matlab.ui.control.button-properties.html#d117e1549488
  4. From within the callback function, use the "app." structure to find the handle to your GUI object that contains the file path string. Then access the string property.
  5. Now you can call your external function with the file path input.
Don't get intimidated. Dive right in and if you get stuck, feel free to ask follow-up questions below as a comment under this answer (share what you tried and why it's not working).
  9 件のコメント
Lucas S
Lucas S 2019 年 4 月 12 日
You mean i have to use exist() in my .m function or in my app code ?
Adam Danz
Adam Danz 2019 年 4 月 12 日
編集済み: Adam Danz 2019 年 4 月 17 日
You could do either (or both). If your .m function is designed to be called by additional callers other than your app, it would be smart to do that in your external file.
Doing it in your app checks the validity before sending the variable. It's more of a conceptual question. I'd do it in the external file.

サインインしてコメントする。

カテゴリ

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