Running a matlab file within appdesigner pushbutton
3 views (last 30 days)
Show older comments
I would like to run a matlab file, which is a program that has several steps including: uses data from text files, multiple functions, and requires some initial user inputs before executing. I have looked up how to do this and I feel like I have already given this enough tries already. I am currently at my callback function to run the program and I really do not understand why the code does not work.
% Button pushed function: RunButton
function RunButtonPushed(app, event)
a = app.aEditField.Value;
b = app.bEditField.Value;
c = app.cEditField.Value;
matrix = [a, b, c];
result = program(matrix);
end
The user puts in 3 numbers, then presses the button and it should work, but the error code is:
Error: File: appname.mlapp Line: 151 Column: 9
Function definition are not supported in this context. Functions can only be
created as local or nested functions in code files.
and for some reason, I also have another error in part of the appdesigner code that I am not able to manipulate, as far as I know:
% Component initialization
methods (Access = private)
Line 199: Parse error at METHODS: usage might be invalid MATLAB syntax.
0 Comments
Answers (1)
Rik
on 21 Jun 2023
This is likely due to an extra or missing end statement. Once such fundamental delimiters get mismatched, the syntax error may be reported in an unrelated section of the code. You will need to post the entire file (attach it to a comment) if you want me to help you find the place where you should apply the fix.
6 Comments
Rik
on 23 Jun 2023
Of course you can, you can call it the same way as any other function: as long as it exists on the path you can just use its name. Exactly like you showed in the snippet in your question. The only thing I notice you should change in that snippet is that you do not store the output of that function anywhere (i.e., the variable result is destroyed when the method returns, miliseconds after it is created).
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!