MATLAB: Array indices must be positive integers or logical values

arrayshear force

t sure where I went wrong.
w = 2.5; % UDL in kN/m
P=w*(3+1.2); % converting UDL to a Point Load, P
a=(3+1.2)/2; % Distance to the centroid
%% Shear Force & Bending Moment
By=P*a/3; % Vertical Loads
Ay=P-By;
x1=[0:0.1:3]; % Range from pin to roller
V1 = -w*x1+Ay;
M1 = -w*x1.^2 + Ay*x1;
x2=[3:0.1:4.2];
V2 = -w*x2+Ay+By;
M2 = (-w*x2.^2)/2 + Ay*x2 + By(x2-3);
%% Plotting the SF and BM Diagram
x=[x1 x2]; V=[V1 V2]; M=[M2 M2];
figure(1); plot(x,v)
figure(2); plot(x,m)
Array indices must be positive integers or logical values.
Error in SF_BM (line 19)
M2 = (-w*x2.^2)/2 + Ay*x2 + By(x2-3);

Best Answer

You're missing the multiplication operator between By and (x2-3).
Related Question