Borrar filtros
Borrar filtros

Arrays intersection with repetition

11 visualizaciones (últimos 30 días)
Meriem Deli
Meriem Deli el 4 de Mayo de 2017
Editada: Bruno Luong el 27 de Sept. de 2018
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

Respuestas (1)

Bruno Luong
Bruno Luong el 27 de Sept. de 2018
Editada: Bruno Luong el 27 de Sept. de 2018
% 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)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by