Borrar filtros
Borrar filtros

How could you find the index number of an answer output?

3 visualizaciones (últimos 30 días)
I have a code that looks like:
for ii=2:length(dep);
dz(ii) = dep(ii)-dep(ii-1);
drho(ii) = sigth(ii)-sigth(ii-1);
end
for ii=1:length(dz);
drhodz(ii) = drho(ii)/dz(ii);
end
max(drhodz)
Is there a way to go back and then see which ii this maximum answer corresponds to? (Does that question make sense? After finding the maximum drhodz I'm trying to work backwards to see at which dz (change in depth) this max occurs.)

Respuesta aceptada

Arnaud Miege
Arnaud Miege el 18 de Jul. de 2011
[max_value, max_idx] = max(drhodz)
The index ii corresponding to the maximum value max_value is given by max_idx.
HTH,
Arnaud

Más respuestas (2)

Sean de Wolski
Sean de Wolski el 18 de Jul. de 2011
Arnaud's reply is correct
To find the indices of multiple maxima:
find(drhodz==max(drhodz));
Also, your for-loops can be easily vectorized with:
dz = diff(dep);
drho = diff(sigth);
drhodz = dz./drho;
  2 comentarios
Chelsey
Chelsey el 18 de Jul. de 2011
Thank you - a much more elegant solution than what I was trying to do.

Iniciar sesión para comentar.


Chelsey
Chelsey el 18 de Jul. de 2011
Thank you both!

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by