I have the matrix A which is similar to :
A = [ 1 1 1 2 2 2; ...
1 2 2 2 2 2; ...
2 2 2 2 2 2; ...
1 1 1 2 2 3; ...
1 1 1 2 3 2; ...
1 2 2 2 3 2; ...
1 2 1 2 1 2]
Now I want to create the vector B which is similar to :
B = [ 1, *, 1, 2, *, *];
The * would mean that the element can be any value. I would use A and B in the following code to obtain a matrix containing the rows for which there is a concordance (ismember).
[~, indx]=ismember(A,B,'rows')
And the desired result would be :
indx = [ 1; 0; 0; 1; 1; 0; 1;] % so B is a member of A for rows 1, 4, 5 and 7
I know it would work if B is equal to [1 1 1 2 2 2], the result would be row 1.
You almost have it. Just work with selected columns:
B = [1 NaN 1 2 NaN NaN ]; %// NaN is used to indicate "don't care", in this case
pos = ~isnan(B); %// positions of actual values
indx = ismember(A(:,pos),B(pos),'rows') %// select columns and apply ismember
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With