필터 지우기
필터 지우기

Arrays intersection with repetition

조회 수: 11 (최근 30일)
Meriem Deli
Meriem Deli 2017년 5월 4일
편집: Bruno Luong 2018년 9월 27일
Hello,
I have two arrays output_max and output_min and I need to get the intersection between the two with the repetitions. Is there any function that can solve this problem but not intersect matlab function because it eliminates all the repetitions.
Thanks for your help

답변 (1개)

Bruno Luong
Bruno Luong 2018년 9월 27일
편집: Bruno Luong 2018년 9월 27일
% random test data
output_min = ceil(30*rand(1,20))
output_max = ceil(30*rand(1,20))
% find the indexes of the intersect
v = intersect(output_min,output_max);
bmin = ismember(output_min,v);
bmax = ismember(output_max,v);
imin = find(bmin);
imax = find(bmax);
% check, both return all the elements of the intersect
% it might be preferable to index by logical arrays bmin, bmax
output_min(imin)
output_max(imax)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by