在某些条件下还原矩阵 [英] reducing matrices under certain conditions

查看:100
本文介绍了在某些条件下还原矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

M是由几个子矩阵Ai组成的矩阵4x2000000,因此Ai(1:3,j)j = 1,...,size(Ai,2)的相同向量.和Ai(4,j)是介于1100之间的值.

M is a matrix 4x2000000 composed of several submatrix Ai such that Ai(1:3,j) is the same vector for j = 1,...,size(Ai,2). and Ai(4,j) are values between 1 and 100.

V = [2 15 21 43]

我的目标是消除M的所有子矩阵Ai,如果Ai(4,:)不包含V的所有值.

my goal is to eliminate all sub-matrix Ai of M, if Ai(4,:) does not contain all the values of V.

此问题的唯一初始数据MV

示例:

M = [1022  3001  4451 1022 1022  3001 1022 3001 3001 1022;
      112    45    10  112  112    45   11   45   99  112;
      500    11    55  500  500    11   88   11    1  500;
        2     6     3    5   71     2    2   71    5   88]  

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;
        10;
        55;
         3]

A4 = [1022;
        11;
        88;
         2]

A5 =[3001;
       99;
        1;
        5]

如果V = [2 71]

预期输出(列的顺序并不重要):

The expected output (order of columns is not important):

[1022 1022 1022 1022 3001 3001 3001;
  112  112  112  112   45   45   45;
  500  500  500  500   11   11   11;
    2    5   71   88    6    2   71]

推荐答案

一种方法-

[~,~,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)))

这篇关于在某些条件下还原矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆