MATLAB中N矩阵的交点

发布于 2025-01-28 10:50:27 字数 357 浏览 1 评论 0原文

我有一个矩阵IntialMat,并且具有其他n个矩阵的结构。我想拥有与矩阵IntialMat相交的矩阵的索引。我该如何在MATLAB中这样做?

例如initialmat = [2,5,88; 55 63 4] 和结构矩阵有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]

我想要的结果是交叉点的值和名称 Matrice或其索引: 具有MAT3的值2(索引3) 带有MATN的值4(索引n)

I have a matrix IntialMat, and I have a structure with N other matrices. I want to have the indices of the matrices that intersect with a least one element of the matrix IntialMat. How can I do that in MATLAB?

For example InitialMat=[2, 5, 88; 55 63 4]
And structure MatriciesStor have N matrices :

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

The result that I want is the value of the intersection and the name
of the matrice or its index:
the value 2 with Mat3 (index 3)
The value 4 with MatN (index N)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还如梦归 2025-02-04 10:50:27

您可以在这样的矩阵上循环:

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

You can loop over the matrices like this:

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");

which gives something like:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文