How to use workspace values as parameters in MatlabFunction?
8 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I would like to ask Matlab Function how to call the values in Workspace Matrix.
This is my Workspace Matrix
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1647736/image.png)
and this is my Matlab Function
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1647741/image.png)
Show This ERR.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1647746/image.png)
0 件のコメント
回答 (1 件)
Dinesh
2024 年 3 月 21 日
Hello,
In MATLAB functions, if you would like to use a variable from the workspace rather than the ones passed as function arguments, you can use the "evalin" function with the first argument as 'base'.
Link to the documentation:
Here's a code snippet:
pmsm = evalin('base', 'pmsm');
p1 = 3 * pmsm.pp;
2 件のコメント
Dinesh
2024 年 3 月 21 日
For code generation, I don't think "evalin" is supported because there is no such concept of a workspace once the code is generated in C. It is expected that the function arguments or any global variables are the ones that are being used within the function.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!