logical to index values convert
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have a set of values, like a = [1 2 3 4 5 6 7 6 5 4 3 2 1]; % 1x13 double
Now, i wish to get the index of value for which numbers are increasing and decreasing.
For this i used,
for i = 1:length(a)-1
out = find(a(i)>a(i+1));
in = find(a(i)<a(i+1));
end
however, it gives me error.
so i tried,
for i = 1:length(a)-1
out = (a(i)>a(i+1));
in = (a(i)<a(i+1));
end
Now, I have logical o/p. How to fetch index numbers from this logical o/p?
0 Commenti
Risposte (1)
Stephan
il 3 Mar 2019
Modificato: Stephan
il 3 Mar 2019
Hi,
try:
a = [1 2 3 4 5 6 7 6 5 4 3 2 1]; % 1x13 double
for i = 1:length(a)-1
out(i) = (a(i)>a(i+1));
in(i) = (a(i)<a(i+1));
end
in = find(in)
out = find(out)
Note that you can get the same reult without a loop:
in_easy = find(diff(a)>0)
out_easy = find(diff(a)<0)
Best regards
Stephan
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrices and Arrays 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!