Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Maneesh
Maneesh le 5 Juil 2018
Commenté : Maneesh le 6 Juil 2018
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

Réponse acceptée

KSSV
KSSV le 5 Juil 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

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by