why do i keep getting 'Subscript indices must either be real positive integers or logicals'?
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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
Antworten (1)
ES
am 1 Okt. 2013
0 Stimmen
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 Kommentar
Walter Roberson
am 1 Okt. 2013
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.
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!