4x1 vector to 2x1 vector with S function
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have written an Level-2 S-function which creates a 2x1 vector from a 4x1 vector, that it, taking out the first 2 elements.
The function “Output()” is:
function Output(block)
block.OutputPort(1).Data = block.InputPort(1).Data(1:2);
Error: Attempt to assign a matrix of dimentions [2x1] to a matrix of
dimensions [4x1].
So I added the following code to the function “Setup()”:
function Setup(block)
block.OutputPort(1).Dimensions = [2,1];
This time the error is:
Invalid dimentsion has been specified for input port 1 of …
Now I am helpless with this problem. Who can help me with this problem?
Thanks Senmeis
0 件のコメント
採用された回答
Shashank
2012 年 9 月 26 日
Hi,
The reason the error is cropping up is because, while the Output Port Dimensions have been explicitly specified, the S-function is relying on implicit inheritance to determine the dimensions of the Input Port. Due to the differing sizes, there's a conflict. By specifying the InputPort dimensions in this way in the setup method:
block.InputPort(1).Dimensions = 4;
you would be explicitly specifying the Input Port dimensions and the S-function should run fine.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Simulink Functions についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!