MATLAB: Graph figure wont show

loopsplotting

clc;clear all;
l=25;
E=200e9;
I=350e-6;
w=6e3;
for x=linspace(0,l/2,25)
y=(-(w*x)/(384*E*I))*(16*(x^3)-24*l*(x^2)+9*(l^3))
end
for x=linspace(l/2,l,26)
y=(-(w*x)/(384*E*I))*(8*(x^3)-24*l*(x^2)+17*x*(l^2)-(l^3))
end
figure
plot(x,y)

Best Answer

If you're absolutely required to use a for loop, just add an index to y
% Clean up
close all;
clc;
clear all;
l=25;
E=200e9;
I=350e-6;
w=6e3;
x1=linspace(0,l/2,25)
for k = 1 : length(x1)
y1(k)=(-(w*x1(k))/(384*E*I))*(16*(x1(k)^3)-24*l*(x1(k)^2)+9*(l^3))
end
x2=linspace(l/2,l,26)
for k = 1 : length(x2)
y2(k)=(-(w*x2(k))/(384*E*I))*(8*(x2(k)^3)-24*l*(x2(k)^2)+17*x2(k)*(l^2)-(l^3))
end
x = [x1, x2];
y = [y1, y2];
plot(x,y, 'bo-')
grid on;