eliminating value out of range

1 visualización (últimos 30 días)
Mayank Lakhani
Mayank Lakhani el 14 de Mzo. de 2016
Comentada: Mayank Lakhani el 15 de Mzo. de 2016
I have two matrix.
A = rand(8,10);
B = rand(8,41);
range = 0.5345 (y+ direction and y- direction, range of elements of A);
i want to take all elements of B which fall in the range of matrix A 's elements. The elements of B which does not fall in the range should be NaN.
  2 comentarios
Matthew Eicholtz
Matthew Eicholtz el 14 de Mzo. de 2016
Editada: Matthew Eicholtz el 14 de Mzo. de 2016
I assume the code snippet you provide is just to demonstrate the size of A and B and not exactly how you create A and B? Because "A = rand(8,10);" will not necessarily yield a range of 0.5345.
Mayank Lakhani
Mayank Lakhani el 15 de Mzo. de 2016
yes, you are right.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 14 de Mzo. de 2016
Declare a logical variable that states when values are in range
inRange = B >= min(A(:)) & B <= max(A(:));
Now assign to nan if outside that range, as you asked:
B(~inRange) = nan;
Or you can extract only those that are in range into a new variable:
BInRange = B(inRange);
Or you can delete those that are not in range, giving a shorter B than the original:
B(~inRange) = [];

Más respuestas (0)

Categorías

Más información sobre Mathematics and Optimization 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