How to add values from array A (n,3) to array B(m,2)based on values equality between m and n?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Dyuman Joshi
2023-7-21
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,:)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!