row indices of an array which is a subset of another array
Show older comments
Eg. b is a matrix of size(17,2). (BIG MATRIX)
b(:,1)= [ 7;6;5;4;4;3;2;1;20;19;18;17;16;20;21;22;23]
b(:,2) = [30;29;28;27;8;9;10;11;8;12;13;14;15;27;26;25;24]
Now, I need the row indices from this array b which has matching entries in a vector a. The size of vector a is smaller than b. But if the indices are repeated, I want the neighboring row entry.
What I mean by neighboring row entry?
lets say a is : [4; 3; 2; 1]. The entries of a will either be in b(:,1) or b(:,2). there would surely not be any intersection. When I search for a in b(:,1) or (b(:,2)), i will get the row indices [5; 6; 7; 8]. (These are the row indices.) When I search for a = [20;21;22;23] in b(:,1), I want it to return the row indices as [14 15 16 17]..
When a is : [7;6;5;4], I want the row indices [1 2 3 4].
"ismember" allows me to return the first or the last row entries. My requirement here is a bit different.
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!