MATLAB: Bezier Curve problem inside for loop

forfunctiongraphloopMATLAB and Simulink Student Suiteplotproblem

Hi, I have a problem when generating multiple points from two x & y functions inside a for loop. If I use the plot function to plot x and y, then the curve will not appear. If I use the scatter function it will plot each point though, but I want a smooth curve.
figure; hold on
for u = 0:.01:10
x = (1-u)^3*1+3*(1-u)^2*u*3+3*(1-u)*u^2*5+u^3*8;
y = (1-u)^3*1+3*(1-u)^2*u*0.5+3*(1-u)*u^2*2.5+u^3*2;
plot(x,y)
scatter(A(1,:),A(2,:))
xlim([0 10])
ylim([0 4])
end
hold off
Also, is there already a built-in function which will achieve what I'm trying to do? If not what would be the best way to create a function to use for future reference?

Best Answer

Hi Michael,
For your case, for is not recommendded. Instead, use vectors and dot operations to get your code working well. The following code should work.
figure; hold on u = 0:.01:10; x = (1-u).^3*1 + 3*(1-u).^2.*u*3 + 3*(1-u).*u.^2*5 + u.^3*8; y = (1-u).^3*1 + 3*(1-u).^2.*u*0.5 + 3*(1-u).*u.^2*2.5 + u.^3*2; plot(x,y) xlim([0 10]) ylim([0 4]) hold off
Related Question