picking maximum difference across entries of row vectors, Part 3

1 visualización (últimos 30 días)
The question is
for each row, take a difference between every possible pair of two elements in the row and returns the maximum difference
Now A can have missing values. For example, A =[ NaN NaN 3 9 4]. In this case the previous solution
vec = sort(A);
B = vec(end)-vec(1);
does not return a correct answer 6. Please advise.
  2 comentarios
alpedhuez
alpedhuez el 6 de Jun. de 2018
Suppose I replace NaN by -infty. Then the problem would be about taking the difference between max and min among nonzero elements for each row.
alpedhuez
alpedhuez el 7 de Jun. de 2018
Editada: alpedhuez el 7 de Jun. de 2018
I can run a loop for each row calculates
max(D(i,:),[],'omitnan')-min(D(i,:),[],'omitnan');
but would hope simpler code.

Iniciar sesión para comentar.

Respuesta aceptada

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan el 7 de Jun. de 2018
A = [NaN NaN 3 9 4 ; 1 100 NaN 34 12];
maxdiffs = max(sort(A,2),[],2) - min(sort(A,2),[],2);

Más respuestas (0)

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by