i have 2 array A and B and i need to check is item of B is available in A
i use this code but make error
code:
for k=1:length(B)
num=B(k)
r1=find(A==num)
if isempty (r1)
error
Index exceeds matrix dimensions.
Error in partiton1 (line 51)
if isempty (r1)

1 comentario

Walter Roberson
Walter Roberson el 26 de En. de 2017
You might possibly have created a variable named "isempty"

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 26 de En. de 2017

1 voto

A better way to check to see if an item in B is available in A is to use
if ismember(B(k), A)
If you are using floating point numbers, unless the numbers were copied from A into B or copied from B into A, then B(k) might not be exactly in A, because two floating point numbers calculated different ways might have different round-off. http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F . If you want to check to see if something "close enough" to B(k) is in A, then use ismembertol()

Más respuestas (0)

Categorías

Etiquetas

Preguntada:

el 26 de En. de 2017

Editada:

el 26 de En. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by