make error when use isempty()

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 Commento

You might possibly have created a variable named "isempty"

Accedi per commentare.

 Risposta accettata

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()

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by