why do i keep getting 'Subscript indices must either be real positive integers or logicals'?
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
hai , i tried to run this code, but it keeps giving me that answer.
r = -0.5 + (0.5+0.5).*rand(1,1)
nn = 1e-3;
d = 1e-6;
k = 1.38e-23;
t = 0.1;
T = 293;
D = ((k*T)/3*pi()*nn*d)
for i = 1 : 100;
x(i+t) = x(i) + (sqrt(2*D*t))*r;
end
for i = 1:100;
y(i+t) = y(i) + (sqrt(2*D*t))*r
end
plot(x,y)
and the error are from
for i = 1 : 100;
x(i+t) = x(i) + (sqrt(2*D*t))*r;
end
for i = 1:100;
y(i+t) = y(i) + (sqrt(2*D*t))*r
end
can someone tell me what is wrong with the codes? well, i am a beginner.
thanks in advance
댓글 수: 0
답변 (1개)
ES
2013년 10월 1일
0 개 추천
you have specified t to be 0.1.
x(i+t) will be x(1.1) for i=1. You cant index arrays like this. Array indices are positive integers starting from 1 in MATLAB.
댓글 수: 1
Walter Roberson
2013년 10월 1일
The notation
x(i+t) =
might tempt you to think that you are constructing a formula relating a function "x" with argument (1.1), with some value. However, in MATLAB, with the exception of some kinds of Symbolic Mathematics, the notation
x(i+t) =
means that the array "x" indexed at the location i+t is to be assigned a value. Indices in MATLAB must be integers starting from 1, but your i+t will seldom be an integer.
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!