Azzera filtri
Azzera filtri

Index Match - distribute a set of data to a larger set

2 visualizzazioni (ultimi 30 giorni)
Hi I have the following 2 arrays A = [9 9 9 10 10 10 11 12 12 12 12 13 14 14 14 15 15 16 16 16 16 17]' B = [10 13 16; 999 900 950]' I am looking for a result set C = [9 9 9 10 10 10 11 12 12 12 12 13 14 14 14 15 15 16 16 16 16 17;0 0 0 999 999 999 0 0 0 0 0 900 0 0 0 0 0 950 950 950 950 0]' I have achieved it using loop and repelem, but i am sure there's got to be a simpler solution. Thanks

Risposta accettata

KSSV
KSSV il 5 Lug 2018
A = [9 9 9 10 10 10 11 12 12 12 12 13 14 14 14 15 15 16 16 16 16 17]' ;
B = [10 13 16; 999 900 950]' ;
C = [9 9 9 10 10 10 11 12 12 12 12 13 14 14 14 15 15 16 16 16 16 17;0 0 0 999 999 999 0 0 0 0 0 900 0 0 0 0 0 950 950 950 950 0]' ;
iwant = zeros(length(A),2) ;
iwant(:,1) = A ;
[c,ia] = ismember(A,B(:,1)) ;
for i = 1:max(ia)
iwant(ia==i,2) = B(i,2) ;
end

Più risposte (0)

Prodotti


Release

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by