Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
Maneesh
Maneesh el 5 de Jul. de 2018
Comentada: Maneesh el 6 de Jul. de 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

Respuesta aceptada

KSSV
KSSV el 5 de Jul. de 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

Más respuestas (0)

Categorías

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

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by