matrix dimension mismatch problem
3 次查看(过去 30 天)
显示 更早的评论
hiii
i have an issue of matrix dimension mismatch..i have this following code.
R=1:1:500;
d=[1 2 3 4];
delB=1;
Bmn=1;
a=1+((delB*d)-(Bmn*d./Rb)).^2;
b=1+(delB*d).^2-(Bmn*d./Rb).^2;
c=1+((delB*d)+(Bmn*d./Rb)).^2;
hmn=1.414*kpqt^2*d*((1./(sqrt(a.*(b+sqrt(a.*c)))))+(1./(sqrt(c.*(b+sqrt(a.*c))))));
XT=tanh(hmn*L);
This is showing matrix dimention mismatch.
plz help me out..
thank u in advance.
0 个评论
回答(2 个)
Star Strider
2020-6-27
The assignment to ‘Rb’ appears to be missing. Since you are using element-wise division wih it, it appears to be a vector, so I created it as a random (1x4) vector to match ‘d’. (Also, ‘kpqt’ and ‘L’ are missing, although they appear to be a scalars.)
Assuming that ‘Rb’ is also a (1x4) vector, do element-wise multiplication:
hmn=1.414*kpqt^2*d.*((1./(sqrt(a.*(b+sqrt(a.*c)))))+(1./(sqrt(c.*(b+sqrt(a.*c))))));
↑ ← HERE
If the undefined variables have different row and column sizes than I assumed here, my Answer may need to change.
2 个评论
Star Strider
2020-6-27
My pleasure!
In that situation, you also need to transpose either ‘d’ or ‘R’ (although not both).
My original Answer remains valid with those changes, since that multiplication needs to be element-wise either way.
.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!