reducing matrices under certain conditions

1 view (last 30 days)
M is a matrix composed of several submatrix Ai such that Ai(1:3,j) is the same vector for j = 1,...,size(Ai,2)
M = [1022 3001 4451 1022 1022 3001 3001 1022 4451 1022;
112 45 10 112 112 45 45 112 10 11;
500 11 55 500 500 11 11 500 55 88;
2 6 6 5 71 2 71 88 2 2]
A1 = [1022 1022 1022 1022;
112 112 112 112;
500 500 500 500;
2 5 71 88]
A2 = [3001 3001 3001;
45 45 45;
11 11 11;
6 2 71]
A3 = [4451 4451;
10 10;
55 55;
6 2]
A4 = [1022;
11;
88;
2]
V = [2 71 6 9]
The only initial data for this problem are M and V .
my goal is to eliminate all sub-matrix Ai of M, if Ai(4,:) does not contains at least numel(V)-2 values of V.
for my example A1, A2 and A3 verify this condition. The expected output (order of columns is not important):
[1022 1022 1022 1022 3001 3001 3001 4451 4451 ;
112 112 112 112 45 45 45 10 10;
500 500 500 500 11 11 11 55 55;
2 5 71 88 6 2 71 6 2]
how to change the following code to solve my problem:
[~,~,idx] = unique(M(1:3,:)','rows') %//'
valid = ismember(M(4,:),V)
valid_idx = accumarray(idx(valid),M(4,valid).',[],@(x) ...
numel(unique(x)))>=numel(V) %//'
out = M(:,ismember(idx,find(valid_idx)))

Answers (0)

Categories

Find more on System Composer 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!