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

Walter Roberson
Walter Roberson 2017년 1월 26일
You might possibly have created a variable named "isempty"

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2017년 1월 26일

1 개 추천

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2017년 1월 26일

편집:

2017년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by