Simulink Port Dimensions Error

Hello everyone, new to Simulink. I have constant A (dimension is 7*7) multiplied by T (dimension is 1). I also have constant block B (size is 7*2) multiplied by an input block Y (dimensions is 2). I am using matrix multiplied for A*T and for B*Y. Equation therefore is M = A*T + B*Y. The using sum block to add them and output is M. The error is “Error in port widths or dimensions. Invalid dimension has been specified for input pot1” any help would be appreciated and even rules on setting the correct port dimensions would be appreciated.

回答(1 个)

VBBV
VBBV 2022-11-22
编辑:VBBV 2022-11-22
M = A.*T + B*Y %

7 个评论

A = randi([0 7],7,7)
A = 7×7
1 7 6 1 1 4 0 5 6 4 2 1 4 1 3 1 7 5 6 4 0 6 0 0 1 6 1 6 1 2 6 7 1 2 4 7 1 6 5 4 3 2 6 5 5 2 0 5 1
T = randi(1);
B = randi([0 7],7,2)
B = 7×2
4 4 2 5 1 7 3 4 1 3 2 2 0 4
Y = randi([0 2],2)
Y = 2×2
2 2 1 1
M1 = A*T %
M1 = 7×7
1 7 6 1 1 4 0 5 6 4 2 1 4 1 3 1 7 5 6 4 0 6 0 0 1 6 1 6 1 2 6 7 1 2 4 7 1 6 5 4 3 2 6 5 5 2 0 5 1
M2 = B*Y %
M2 = 7×2
12 12 9 9 9 9 10 10 5 5 6 6 4 4
M = [M1,M2] % try this instead
M = 7×9
1 7 6 1 1 4 0 12 12 5 6 4 2 1 4 1 9 9 3 1 7 5 6 4 0 9 9 6 0 0 1 6 1 6 10 10 1 2 6 7 1 2 4 5 5 7 1 6 5 4 3 2 6 6 6 5 5 2 0 5 1 4 4
M = A*T + B.*Y % this operation is not possible
Arrays have incompatible sizes for this operation.
Thanks for your reply! So are you saying it cannot be solved?
No, you can change the matrix Y to desired size as
A = randi([0 7],7,7);
T = randi(1);
B = randi([0 7],7,2);
Y = randi([0 2],2,7); % change the size of Y (by zero padding)
M1 = A*T ; %
M2 = B*Y ; %
% M = [M1,M2]; % try this instead
M = A*T + B*Y %
M = 7×7
5 7 6 9 5 7 10 14 15 10 14 10 10 17 15 20 2 11 19 14 15 15 24 9 13 19 19 19 6 5 12 6 2 1 10 13 16 7 15 9 13 17 6 13 8 15 7 7 16
OR use Matrix concatenator and selector blocks in simulink to include them as
M = [M1,M2];
Thank you! So in the M block in Simulink, do I enter 7 or 7*7 in the port dimensions field?
7x7, because the resulting size of M is 7x7
Thanks for your response! For some reason I am still getting an error that the size do not match. I tried reshaping Y which is a 2*1 matrix using Simulink block reshape.
Change the size of array Y from 2 x1 to 2 x7 as below
A = randi([0 7],7,7);
T = randi(1);
B = randi([0 7],7,2);
Y = randi([0 2],2,1) % change the size of Y (by zero padding)
Y = 2×1
1 1
Y = [Y(1) 0 0 0 0 0 0;Y(2) 0 0 0 0 0 0] % change it 2 x 7 by adding zeros
Y = 2×7
1 0 0 0 0 0 0 1 0 0 0 0 0 0
M = A*T + B*Y %
M = 7×7
5 7 4 6 7 6 4 5 5 6 0 7 0 6 13 5 6 3 4 6 1 16 6 1 4 0 1 6 14 7 0 7 1 3 0 18 1 3 0 3 2 3 10 3 4 3 5 3 7

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Simulink Functions 的更多信息

产品

版本

R2019b

提问:

2022-11-22

评论:

2022-11-23

Community Treasure Hunt

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

Start Hunting!

Translated by