finding forward direction in matlab
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I want to write a script for separate forward and backward directions for animal position in a linear track. This is simplified vector.
a = [1 3 5 7 9 10 8 6 4 3 2 3 5 6 7 8 9 7 5 3 2 1];
m = length(a);
for i = 2: m-1
if a(i) >= 1 && a(i-1) > i && a(i+1) > a(i)
fstart (i) = a(i-1);
end
end
for j = 2: m-1
if a(j+1) <= 10 && a(j+2) >= a(j+1) && a(j) < a(j+1)
fend (j) = a(j-1);
end
end
The two vectors I want to create is fstart = [1 2] and fend = [10 9] so that later I can combine to have forward vectors [1 3 5 7 9 10] and [ 2 3 5 6 7 8 9].
Please advise me where is wrong.
Thanks in advance!
0 Commenti
Risposte (1)
KALYAN ACHARJYA
il 12 Mag 2020
Modificato: KALYAN ACHARJYA
il 12 Mag 2020
Please use the another index varibale name inside if statement, like
k=1;
for i=2: m-1
if a(i)>=1 && a(i-1)>i && a(i+1)>a(i)
fstart(k)=a(i-1);
k=k+1;
end
end
So that it avoides those extra zero ( MATLAB fills zero in undefined index value of the array). Rest, just use the correct conditional statement in if condition.
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!