Replace an element in a matrix if it's a member of an array with zero

조회 수: 1 (최근 30일)
Ismaeel
Ismaeel 2016년 12월 14일
댓글: Ismaeel 2016년 12월 14일
I have a matrix A and an array B, I want to find any element in A that exist in B and replace it with zero. Any idea? Thanks

채택된 답변

michio
michio 2016년 12월 14일
ismember function can do the job. As it's stated in the doc page, "Lia = ismember(A,B) returns an array containing logical 1 (true) where the data in A is found in B."
Please try the following do see what it does.
b = magic(4)
a = [1,2,3,4];
I = ismember(b,a)
b(I) = 0

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by