Intersection of three and more arrays

8 visualizaciones (últimos 30 días)
Baisseyev Miram
Baisseyev Miram el 15 de Nov. de 2018
Comentada: Baisseyev Miram el 16 de Nov. de 2018
Hi, is it possible in matlab to find intersection of three and more arrays and index of intersection value in each of three array? Like [C,ia,ib] = intersect(A,B) but for three or more arrays.

Respuesta aceptada

Bruno Luong
Bruno Luong el 15 de Nov. de 2018
My FEX returns the index of the arrays
  8 comentarios
Bruno Luong
Bruno Luong el 15 de Nov. de 2018
Editada: Bruno Luong el 15 de Nov. de 2018
IIUC, what you want is the common element with the lowest max indexes over all the set.
a = [5,6,4,7,8],
b = [7,8,6,5,4],
c = [4,8,5,6,7],
sets = {a,b,c};
nset = length(sets);
idx = cell(1,nset);
[s,idx{:}] = mintersect(sets{:});
idx = cat(1,idx{:});
imax = accumarray(repmat((1:length(s))',nset,1),idx,[],@max);
[~,iminmax] = min(imax);
firstelem = s(iminmax) % returns 5
Baisseyev Miram
Baisseyev Miram el 16 de Nov. de 2018
Yes, thank you very much for spending your time

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical 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