Return subscripts of common rows for multi-dimensional matrix?
Show older comments
I have a 8x2 matrix, A, and a 133x2x5 matrix, B. I want to return the the layer in B in which a row in A matches a row in B. How can I do that? I tried using intersect and ismember but have not had any luck thus far. Having a hard time with the matrix being multi-dimensional.
4 Comments
Guillaume
on 13 Jul 2018
Is it the location, row, col and layer of any B element that is also in A?
Or the row and layer of the 1x2x1 rows of B that are also rows of A?
Andrew Poissant
on 13 Jul 2018
Guillaume
on 13 Jul 2018
And you don't care about which is the row in B that match a A row in that layer?
Andrew Poissant
on 13 Jul 2018
Accepted Answer
More Answers (1)
dpb
on 13 Jul 2018
ix=mod(find(all(ismember(A,B),2)),size(A,3));
4 Comments
Guillaume
on 13 Jul 2018
I'm not sure I understand the logic of this, but isn't this guaranteed to return some 0 ix because of the mod?
Andrew Poissant
on 13 Jul 2018
dpb
on 13 Jul 2018
It is dpb's and it's supposed to be zero...the "fixup" is
ix(ix==0)=size(A,3);
I posted it as much as a lark as anything... :) G's is a much more legible and therefore maintainable approach.
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!