在MATLAB中识别满足阈值的数组中元素的方形子矩阵

Ans*_*nsh -1 matlab matrix threshold

我有一个矩阵(大约342乘342)表示C_{ij},我想根据条件识别原始的矩形子矩阵C_{ij}.我正在使用MATLAB

例如,如果我有矩阵C_{ij}:

C = 1     0.7    0.8
    0.7   1      0.5
    0.8   0.5    1
Run Code Online (Sandbox Code Playgroud)

并且rho = 0.6然后我希望我的代码识别的正确的方形子矩阵是:

C = 1     0.7    0.8
    0.7   1      0.5
    0.8   0.5    1
Run Code Online (Sandbox Code Playgroud)

我不确定如何/最好的方法是在MATLAB中做到这一点?虽然我现在使用的矩阵是对称的,但我更倾向于一种不假设的解决方案.

Adr*_*aan 7

C = rand(342,342);
rho = 0.6;
res = C(C>rho); %// contains all values that are above the threshold
[row,col,val] = find(res); %// returns the indices.
Run Code Online (Sandbox Code Playgroud)

row会包含你的i,col你的j,但我要小心不要使用i或j作为变量.val包含相应的值,但您可以省略它以释放RAM,因为您也可以使用C(row,col)它来获取值.

如果您的矩阵是对称的,您可以使用:

[rowt,colt,val] = find(triu(C)>rho); %// find only in the upper triangle
row = [rowt;colt]; %// flip rows and columns to obtain all results
col = [colt;rowt]; %// flip rows and columns to obtain all results
Run Code Online (Sandbox Code Playgroud)

为了您的编辑:

IdxR = find(diff(unique(rows))==1,1,'first');
IdxC = find(diff(unique(columns))==1,1,'first');
Result = C(1:IdxR,1:IdxC);
Run Code Online (Sandbox Code Playgroud)