How to plot a function in a for loop?
조회 수: 1 (최근 30일)
이전 댓글 표시
n=3;
for i=1:n+1 %this loop returns 4 curves, I want to plot them on a single graph
f{i} = @Bezier;
B=Bezier(n,i-1);
end
%I also want to plot the sum of the 4 curves (i.e. the curve that was generated at i=1 + the one at i=2...etc) (Their sums should be equal 1 across the range)
%This is the function code mentioned above
function [B]=Bezier(n,i)
figure; hold on
u=0:0.001:1;
B=factorial(n)/(factorial(i)*factorial(n-i))*u.^i.*(1-u).^(n-i); %bezier curves function
plot(u,B,'.')
end
%I can combine the curves in the function file but I don't know how to do it when I am calling the function
%and the sum of all graphs at any point should equal 1
댓글 수: 0
채택된 답변
Torsten
2022년 2월 25일
편집: Torsten
2022년 2월 25일
function main
n = 3;
u = 0:0.001:1;
for i = 1:n+1 %this loop returns 4 curves, I want to plot them on a single graph
B{i} = Bezier(u,n,i-1);
end
plot(u,[B{1};B{2};B{3};B{4};B{1}+B{2}+B{3}+B{4}])
end
function B = Bezier(u,n,i)
B = factorial(n)/(factorial(i)*factorial(n-i))*u.^i.*(1-u).^(n-i); %bezier curves function
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!