Clear Filters
Clear Filters

How can i retrieve only the indices of elements within a matrix subset?

2 views (last 30 days)
Hi,
I have a large matrix, C, and a matrix subset, Csub. I want to find the indices of the elements of Csub in C. So essentially, where Csub is in C. I get close with "intersect" but the problem is that I only want the indices of Csub in C, and intersect returns the indices of any element in C who's value is also found in Csub. Is there a way to restrict "intersect" to only the indices that directly correspond to the boundaries (not sure if that's the correct word) of Csub?
For example, if I have the following 2x5 matrix:
C = [1,2,3,4,5;1,2,3,4,3]
And the subset Csub corresponds to elements with linear indices 5 and 6, what is a way to retrieve these indices without also retrieving the index that lies outside of the subset (element with a value of 3 as well, with linear index of 10 in this case)?
  1 Comment
Rik
Rik on 14 Jun 2017
You could use a convolution and search for values that are exactly 1. Due to rounding that might not work for very large subsets, but in cases like your example it should work.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!