How to run a function in app designer?
19 ビュー (過去 30 日間)
古いコメントを表示
Here's the basic interface of my app so far, I'm trying to figure out how to create code so that a function will take my inputs from the edit field boxes, run the function, and display the result in the result section of the interface.
For example, in this case, the user would input the values into the edit field boxes, hit the body button (it would run the earthtobodyFunction) and then spit out the value below the result text.
Here's the interface and my function.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1621778/image.png)
function Fb = earthbodyFunction(psi,phi,theta,m,g)
Fe = [0; 0; (m*g)];
Fe1 = [1,0,0;
0,cos(phi),sin(phi);
0,-sin(phi),cos(phi)];
Fe2 = [cos(theta),0,-sin(theta);
0,1,0;
sin(theta),0,cos(theta)];
Fe3 = [cos(psi),sin(psi),0;
-sin(psi),cos(psi),0;
0,0,1];
Fb = Fe.*Fe1.*Fe2.*Fe3;
end
0 件のコメント
回答 (2 件)
Walter Roberson
2024 年 2 月 20 日
psi = app.EditField_psi.Value;
phi = app.EditField_phi.Value;
theta = app.EditField_theta.Value;
m = app.EditField_m.Value;
g = app.EditField_g.Value;
Fb = earthbodyFunction(psi,phi,theta,m,g);
app.TestField_Fb.Value = Fb;
0 件のコメント
Anjaneyulu Bairi
2024 年 2 月 20 日
Hi,
To add custom functions in appdesigner , you can try below steps.
- Click on Code view, and on the left side you can see "codebrowser." In that, by clicking on the functions tab and clicking on the "+" icon, you can add a function in the app.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1621968/image.png)
Alternatively, if you prefer to code directly:
- While in the Code View, you can elegantly write your code by navigating to the methods (Access=private) block. For example, I have added a function named "func".
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1621973/image.png)
- Now , you can add callback function to button ,this callback function can invoke your custom function and subsequently, you can assign the results to a text label field or any other component of your choice.
I hope this helps to resolve your query.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!