Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Subscript indices must either be real positive integers or logicals.

조회 수: 1 (최근 30일)
Muntasir AlAtoom
Muntasir AlAtoom 2020년 10월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
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?

답변 (1개)

KSSV
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
Muntasir AlAtoom
Muntasir AlAtoom 2020년 10월 20일
when I run it in this way I get this massage:
KSSV
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

태그

제품


릴리스

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by