Size mismatch when i am using simulink

Greetings all, i am currently using simulink to do a project, however when i run the model the mismatch error has occured, below is the code an d details of the error:
Size mismatch (size [1 x 1] ~= size [2 x 10]). The size to the left is the size of the left-hand side of the assignment. Function 'MATLAB Function2' (#370.215.216), line 9, column 1: "u"
can anyone help me to fix this problem? many thanks!!!
function u = fcn(x,y,K,P,u, Theta,Pstore)
for i=2:10
h=[x(i-1);1];
K=P*h*inv(h'*P*h+u);
Theta(:,i)=Theta(:,i-1)+K*(y(i)-h'*Theta(:,i-1));
P=(eye(2)-K*h')*P/u;
Pstore(:,i-1)=[P(1,1),P(2,2)];
end
u=Theta;

 採用された回答

Jonas
Jonas 2021 年 6 月 17 日

0 投票

You have an input named 'u' and an output named 'u', with different sizes.
On line 9, the compiler thinks you are assigning the [2x10] matrix 'theta' to the [1x1] input 'u'.
Rename the output 'u'.

1 件のコメント

Song Lyu
Song Lyu 2021 年 6 月 17 日
How dumb am i...
Thank you!!

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

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2021 年 6 月 17 日

コメント済み:

2021 年 6 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by