MATLAB Answers

Matrix input/output to a Matlab function block in simulink

23 ビュー (過去 30 日間)
Femi Bolarinwa
Femi Bolarinwa 2020 年 10 月 23 日
コメント済み: Femi Bolarinwa 2020 年 10 月 26 日
I need help creating a MATLAB function block in simulink. How do i make a MATLAB function block take in a large matrix from the workspace as its input (say a 1000 by 15 matrix), and also give its output as a matrix?

  2 件のコメント

Mathieu NOE
Mathieu NOE 2020 年 10 月 23 日
hi
simply creat that input matrix in the workspace (do it from a maytlab script if needed)
if that matrix is "A" then in simulink use the constant bloc or DSP constant block with A as argument (edit box)
now what you do in the simulink file must be coherent with a matrix input ... not every bloc / function accept m by n size inputs.
Femi Bolarinwa
Femi Bolarinwa 2020 年 10 月 26 日
Thanks

サインインしてコメントする。

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 23 日
An alternate way is to create a parameter input in the MATLAB function block and give it the same name as the base workspace variable. Refer to Kaustubha's answer here: https://www.mathworks.com/matlabcentral/answers/40701-using-workspace-data-in-matlab-function-block-simulink and follow the instructions after "Besides TAB's solution, ...". Following link will also be helpful
A slight advantage is that you don't need to create an additional block in your model.

  5 件のコメント

表示 2 件の古いコメント
Femi Bolarinwa
Femi Bolarinwa 2020 年 10 月 25 日
So the first MATLAB function block takes in 1000*15 matrix as parameter input like you suggested. The output "CalcLoad" is 1000*1 and X is 12*1. The eventaul output X_f is also 12*1. There is no sample time, just matrix operation but MATLAB keep insisting there must be a discrete sample time.
Ameer Hamza
Ameer Hamza 2020 年 10 月 26 日
You may try to change the solver mode from variable to discrete. Click the solver name at the lower right corner of the Simulink window. Click the solver setting button, and in the solver selection menu, select "Fixed-step".
Femi Bolarinwa
Femi Bolarinwa 2020 年 10 月 26 日
Thanks a lot

サインインしてコメントする。

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2020 年 10 月 23 日
Use a Constant block, specify the value as the variable in the base workspace, then you will be able to use it, no matter what is the size of the matrix. When you construct the code for the MATLAB Function block, click the "Edit Data" button and specify the size of input and output variable.

  1 件のコメント

Femi Bolarinwa
Femi Bolarinwa 2020 年 10 月 26 日
Thanks. This worked too

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by