excluding zeros from min of matrix column

3 visualizaciones (últimos 30 días)
Brad Sullivan
Brad Sullivan el 14 de Mzo. de 2019
Editada: Brad Sullivan el 14 de Mzo. de 2019
[r, c] = find(A==min(A(i:n,i)),1);
this statement is being used to find thelocation of the minimum of a certain column given a for loop incrementing i. Can I edit this statement to exclude zero entries? On matrices without negative values, it is setting the minimum to zero, and I am not sure where or how I could include A~=0 in this statement.
  2 comentarios
Stephen23
Stephen23 el 14 de Mzo. de 2019
Editada: Stephen23 el 14 de Mzo. de 2019
Either:
  1. use indexing to subsample the data to exclude the zeros, or
  2. replace the zeros with +Inf,
then find the minimum.
Brad Sullivan
Brad Sullivan el 14 de Mzo. de 2019
Editada: Brad Sullivan el 14 de Mzo. de 2019
Thank you for this! I devised the following solution to find a way around this that implemented subsampling the data which seems to work:
tempRow = A(i:n,i);
[r, c] = find(tempRow==min(tempRow(tempRow~=0)));
p = r;
if i > 1
p = r+i-1;
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by