how to call matrix from workspace into simulink and return it in workspace?
6 views (last 30 days)
Show older comments
Hi
How can I call a matrix from workspace in matlab into simulink and do some mathematical operations on it and return it in matlab workspace?
for example:
I use "simin" block in simulink to get the matrix A=[1 2 3], then with a "matlab function" block I want to get the size of the matrix A the matrix and finally using a "simout" block I want to export the size of A into the workspace, but it doesn't work.
I have also attached the screenshot.
Can someone help please?![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/246108/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/246108/image.png)
0 Comments
Answers (1)
Rajanya
on 29 Jan 2025 at 13:54
The error is likely in the definition of the function in the MATLAB function block itself since 'B' is never defined in the function. Output arguments need to be fully defined for code generation. Also, since 'B' (which is supposed to be the output of the function) is never defined, Simulink fails to determine the size and type of output from the MATLAB function block, leading to such errors.
Changing the function definition to the following will remove the errors:
function B = fcn(A)
%#codegen
u=size(A);
B = u(1,1)+u(1,2);
I hope this helps. Thanks.
0 Comments
See Also
Categories
Find more on Simulink Functions 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!