How to add values from array A (n,3) to array B(m,2)based on values equality between m and n?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
YAAQOB AL-JAMALI
el 21 de Jul. de 2023
Comentada: Dyuman Joshi
el 26 de Jul. de 2023
I have two arrays A and B of different sizes, wherein, array B is a subarray from array A. Therefore, I want to pad the array B with values from the third colums of array A(:,3) based on the equality comparison of B(ii,1) and A(ii,1).Resulted array should be B(m,3)
I have attached examples of dataset for the 2 arrays A and B namely pathInfo,and pathReduced respectively.
0 comentarios
Respuesta aceptada
Dyuman Joshi
el 21 de Jul. de 2023
You can directly get the desired result -
load('pathReduced.mat')
load('pathInfo.mat')
pathReduced
inpath
%Check which elements in the 1st column of inpath are common to the
%elements in the 1st column of pathReduced
idx = ismember(inpath(:,1),pathReduced(:,1));
%Get the sub array from inpath (as pathReduced is sub array of inpath as
%mentioned in the problem above)
out = inpath(idx,:)
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!