Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Subscript indices must either be real positive integers or logicals.
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to write a programm that draws a quartic Bezier Curve,
so this is it:
clc
close all
clear all
n=5;
axis([0 100 0 100])
[p]=ginput(n)
c=[];
f=[];
for t=0:0.0001:1
f(t)=p(1,:)*(1-t)^4+p(2,:)*t*(1-t)^3+p(3,:)*(t^2)*(1-t)^2+p(4,:)*(1-t)*t^3+p(5,:)*t^4;
c=cat(1,c,f);
end
line(c(:,1),c(:,2))
line(p(:,1),p(:,2))
so when I run it I get this massage:
how can I solve the problem?
댓글 수: 0
답변 (1개)
KSSV
2020년 10월 20일
편집: KSSV
2020년 10월 20일
clc
close all
clear all
n=5;
axis([0 100 0 100])
[p]=ginput(n)
c=[];
f=[];
T=0:0.0001:1 ;
for i = 1:length(T) % changed here, your indices cannot be fractions. They should be positive integers
t = T(i) ;
f(i)=p(1,:)*(1-t)^4+p(2,:)*t*(1-t)^3+p(3,:)*(t^2)*(1-t)^2+p(4,:)*(1-t)*t^3+p(5,:)*t^4;
c=cat(1,c,f);
end
line(c(:,1),c(:,2))
line(p(:,1),p(:,2))
댓글 수: 2
KSSV
2020년 10월 20일
clc
close all
clear all
n=5;
axis([0 100 0 100])
% [p]=ginput(n)
p = rand(n,2) ;
T=0:0.0001:1 ;
f=[length(T),2];
for i = 1:length(T)
t = T(i) ;
f(i,:)=p(1,:)*(1-t)^4+p(2,:)*t*(1-t)^3+p(3,:)*(t^2)*(1-t)^2+p(4,:)*(1-t)*t^3+p(5,:)*t^4;
end
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!