Azzera filtri
Azzera filtri

Generate a cell array with index values from two separate vectors

1 visualizzazione (ultimi 30 giorni)
I have two cell arrays
x = {99983, 885735, 8993, 63742, 37443, 38437, 67638}
y = {99983, 885735, 99983, 885735, 8993, 63742, 37443, 38437, 67638, 8993, 99983, 885735, 8993, 63742, 99983, 885735, 8993, 63742, 37443, 38437, 67638,37443, 38437, 67638, 63742, 37443, 38437, 67638}
I would like to obtain a new cell array, z, such that:
z = {[1 3 11], [2 4 12 16], [5 11 13 17], [6 14 18 25], [7 19 22 26], [8 19 22 26], [9 21 24 28]}
In other words, z contains the index locations of the x elements in y

Risposta accettata

Ameer Hamza
Ameer Hamza il 24 Mag 2020
Try this
x = {99983, 885735, 8993, 63742, 37443, 38437, 67638};
y = {99983, 885735, 99983, 885735, 8993, 63742, 37443, 38437, 67638, 8993, 99983, 885735, 8993, 63742, 99983, 885735, 8993, 63742, 37443, 38437, 67638,37443, 38437, 67638, 63742, 37443, 38437, 67638};
[~, idx] = ismember([y{:}], [x{:}]);
z = splitapply(@(x) {x}, 1:numel(y), idx);

Più risposte (0)

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by