MATLAB: Matrix dimension must agree

matrix dimention must agree

Ihave a code
xd=-(sqrt(R²-ho²)):0.5:x3;
xd1=x3;
yd1=y3;
xd2=-(sqrt(R²-ho²));
yd2=ho;
yd=(((xd-xd1)./(xd2-xd1)).*(yd2-yd1))+(yd1);
plot(xd,yd,'k')
The result is:
Eror using .* Matrix dimensions must agree.
Please help mee ?
*code formatted by Adam Danz; the squared superscripts are ambiguous (^2 or .^2) so I left them as-is – AD

Best Answer

In this line
yd = (((xd-xd1)./(xd2-xd1)).*(yd2-yd1))+(yd1);
% ^^
The terms to the left and right of .* are not the same size. The dot-asterisk notation specifies element-wise multiplication where x .* y is interpretted as x(i) * y(i). That requires that x and y are the same size.
The two lines below must produce the same output.
size(((xd-xd1)./(xd2-xd1)))
size((yd2-yd1))