필터 지우기
필터 지우기

how i can use x(t) & ... in my program

조회 수: 14 (최근 30일)
behnam
behnam 2012년 2월 16일
편집: Matt J 2013년 10월 15일
i use this code but matlab show me an eror how i can fix this eror
also i want plot (>) with angle fee how i can do that ?
clear all
t=0;
x(t)=input('Enter X(0) =');
y(t)=input('Enter Y(0) =');
fee(t)=input('Enter Fee(0) =');
for (x(t+1)~=10)&&(fee(t+1)~=90)
t=t+1;
plot(x(t),y(t),'>');
x(t+1)=x(t)+cos(fee(t)+teta(t))+sin(teta(t))*sin(fee(t));
y(t+1)=y(t)+sin(fee(t)+teta(t))-sin(teta(t))*cos(fee(t));
fee(t+1)=fee(t)-asin((2*sin(teta(t)))/4);
end

채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 16일
MATLAB does not permit the value 0 to be used as a vector index. Vector indexes must be integers 1 or greater.
Requesting '>' as the plot marker gets you a right-pointing triangle. If you want an open arrow instead, then you will need to draw in the markers yourself at each location.

추가 답변 (2개)

behnam
behnam 2012년 2월 16일
thank you but now i receive this message : ??? Attempted to access x(2); index out of bounds because numel(x)=1.
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 2월 16일
If, hypothetically, MATLAB allowed x(0) to be defined, then you would still have had this problem anyhow, because of your line
for (x(t+1)~=10)&&(fee(t+1)~=90)
which, besides being syntactically invalid for a "for" loop, would attempt to access x(1) at a time when only x(0) had been defined.
Your code is non-functional in such a manner that we cannot make a reasonable guess about what you were attempting to write.

댓글을 달려면 로그인하십시오.


behnam
behnam 2012년 2월 16일
i mean i edited my m-file code as below :
please if possible edit my m-file into correct
clear all
t=1;
x(t)=input('Enter X(0) =');
y(t)=input('Enter Y(0) =');
fee(t)=input('Enter Fee(0) =');
plot(x(t),y(t),'>');
i=1;
if (x(t)~=10)&&(fee(t)~=90)
x(t+1)=x(t)+cos(fee(t)+teta(t))+sin(teta(t))*sin(fee(t));
y(t+1)=y(t)+sin(fee(t)+teta(t))-sin(teta(t))*cos(fee(t));
fee(t+1)=fee(t)-asin((2*sin(teta(t)))/4);
plot(x(t+1),y(t+1),'>');
t=t+1;
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 2월 16일
Do you want a "while" loop instead of "if" ? If so then you would move the plot() to after the "while" and would
plot(x, y, '>')
However! See
http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
as otherwise your loop might never terminate.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by