我有一個 matrix 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)
uj5u.com熱心網友回復:
您可以像這樣遍歷矩陣:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/475407.html
下一篇:從兩個矩陣中提取相同的列
