logical to index values convert
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Stephan
el 3 de Mzo. de 2019
Editada: Stephan
el 3 de Mzo. de 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 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!