在 MATLAB 中与 N 个矩阵相交

Intersection with N matrices in MATLAB

我有一个矩阵IntialMat,我有一个包含 N 个其他矩阵的结构。我想要矩阵的索引与矩阵的至少一个元素相交 IntialMat。我如何在 MATLAB 中做到这一点?

例如InitialMat=[2, 5, 88; 55 63 4] 并且结构 MatriciesStor 有 N 个矩阵:

Mat1=[1, 55,12; 45 78]
Mat2=[12, 14; 42,165]
Mat3=[2,18,11; 13,80; 10, 99]
.
.
.
.
.
.
MatN=[4, 77;63,20]

我要的结果是交集的值和名字 矩阵或其索引: Mat3 的值 2(索引 3) MatN 的值 4(索引 N)

您可以像这样遍历矩阵:

IntialMat = randi(100, 3);
for i = 1:10
    MatriciesStor{i} = randi(100, 3);
end

% Now compare all Mats against IntialMat
for i = 1:10
    inter = intersect(MatriciesStor{i},IntialMat);
    if ~isempty(inter)
        fprintf("\nMatrix %d has intersections: %d", i, inter);
    end
end
fprintf("\n");

给出类似的东西:

Matrix 1 has intersections: 18 
Matrix 2 has intersections: 46 
Matrix 3 has intersections: 18 38 
Matrix 7 has intersections: 79 
Matrix 8 has intersections: 51 
Matrix 9 has intersections: 75