Error'incorrect dimensions for matrix multiplication'

1 回表示 (過去 30 日間)
Ancy S G
Ancy S G 2022 年 3 月 1 日
コメント済み: VBBV 2022 年 3 月 30 日
phis=3;phib=8;
zeta=-.95:0.5:10;
Eg=[-2.9583 5.2519 -6.5456 5.2455 -0.4883 -7.0614 -6.5562];
xi=[1 1 1 1 1 1];
for n=1:1:6
if Eg(:,n)>=zeta
zeta=xi/phis-1;
F=xi*log(1+zeta)+phis*(Eg(n,:)-zeta);
elseif Eg(:,n)<zeta
zeta=xi/phib-1;
F=xi*log(1+zeta)+phib*(Eg(n,:)-zeta);
else
end
end
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
plot(zeta,F,'*')
How to correct the dimension of this matrix

回答 (1 件)

VBBV
VBBV 2022 年 3 月 1 日
編集済み: VBBV 2022 年 3 月 1 日
phis=3;
phib=8;
zeta=-.95:0.5:10;
Eg=[-2.9583 5.2519 -6.5456 5.2455 -0.4883 -7.0614 -6.5562]
Eg = 1×7
-2.9583 5.2519 -6.5456 5.2455 -0.4883 -7.0614 -6.5562
xi=[1 1 1 1 1 1];
for n=1:1:6
if Eg(:,n)>=zeta
zeta=xi/phis-1;
F(:,n)=xi.*log(1+zeta)+phis*(Eg(:,n)-zeta); % accessing incorrect index
elseif Eg(:,n)<zeta
zeta=xi/phib-1;
F(:,n)=xi.*log(1+zeta)+phib*(Eg(:,n)-zeta);
else
end
end
plot(zeta,F,'*')
check the sizeof Eg matrix
  2 件のコメント
Ancy S G
Ancy S G 2022 年 3 月 17 日
Thank you
VBBV
VBBV 2022 年 3 月 30 日
If this solved your problem, please accept the answer :)

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

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by