Element-wise set operations

조회 수: 3 (최근 30일)
Gabriel Stanley
Gabriel Stanley 2022년 12월 2일
댓글: Gabriel Stanley 2022년 12월 3일
Given twovectors A & B, I'm trying to figure out how to get a numel(A)-by-numel(B) logical array C wherein C(i) is the result of ismember(B',A(i)) without using a for loop. I've tried feeding repmat'ed and tranposed versions of A & B into ismember, but to no avail.
How can I achieve the same result as
A = randi(11, [500 1]);
B = randi(10, [250 1]);
C = false(500,250)
for i = 1:numel(A)
C(i) = ismember(B',A(i));
end
without the for loop? If the answer is arrayfun, is that really any faster than a for loop?

채택된 답변

Voss
Voss 2022년 12월 2일
  댓글 수: 1
Gabriel Stanley
Gabriel Stanley 2022년 12월 3일
It works, but I don't understand why it works while the un-looped ismember use didn't. If I have time later I'll try to dig into that and improve my understanding. In the meantime, thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by