Ignoring when indexing value positions are invalid
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi
I get and error when running this code, is it possible to ignore when position is invalid at just let the code proceed?
so it stille includes as many as possible?
thanks
for o = 1:length(mBall)
if mBall(o,4:5) == 0
mBall(o,6) = 1;
elseif sum(displace(o-25:o+25,1)) < 2
mBall(o,6) = 3;
else
mBall(o,6) = 0;
end
end
%Index in position 1 is invalid. Array indices must be positive integers or logical values.
%Error in Velocity (line 93)
%elseif sum(displace(o-25:o+25,1)) < 2
2 Commenti
Risposte (2)
Image Analyst
il 1 Apr 2019
Try this
for k = 1 : length(mBall)
if all(mBall(k,4:5) == 0)
mBall(k,6) = 1;
elseif k >= 26
if sum(displace(k-25 : k+25,1)) < 2
mBall(k,6) = 3;
else
mBall(k, 6) = 0;
end
else
mBall(k,6) = 0;
end
end
0 Commenti
Jan
il 1 Apr 2019
"when o = 24, it will only take the 24 first indces into account"
for k = 1:length(mBall)
if mBall(k, 4:5) == 0
mBall(k, 6) = 1;
elseif sum(displace(max(1, k-25):k+25,1)) < 2
mBall(k, 6) = 3;
else
mBall(k, 6) = 0;
end
end
"o" can be confused with "O" or "0", so "k" is used here instead.
You should not "ignore" an error, but create some code to avoid it. Here the index cannot be smaller than 1, so set 1 as minimal index explicitly. Or maybe:
elseif k > 25 && sum(displace(k-25:k+25,1)) < 2
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!