필터 지우기
필터 지우기

Running a matlab file within appdesigner pushbutton

조회 수: 2 (최근 30일)
I
I 2023년 6월 21일
댓글: Rik 2023년 6월 23일
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.

답변 (1개)

Rik
Rik 2023년 6월 21일
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
I
I 2023년 6월 23일
Do you mean I cannot run a matlab program within appdesigner? I was developing an interface for this exact purpose.
Rik
Rik 2023년 6월 23일
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).

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

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by