matlab 组织结果,这样它们就不会在循环中被覆盖

matlab organize results so they do not overwrite in recurent loop

我想整理这些结果并以某种方式追踪它们。在达到 2 号矩阵之前,我不知道如何继续前进。 还有可能有更好的方法做我想做的事,这会让我很开心。

编辑:我希望能够看到更多层次递归的结果。问题是我不知道如何将结果从第 10 级发送到第 1 级,以便它可以用于整个程序。此外,我不确定我是否可以追踪它们以了解每个结果的所有 i 的所有值,这意味着删除了哪些 lines/columns。

clc
close all
clear all
fclose('all');
d2=[0   -1.165  -3.5493 -2.3828 -1.1464
1.165   0       -2.3843 -1.2178 0.0186
3.5493  2.3843  0       1.1665  2.4029
2.3828  1.2178  -1.1665 0       1.2364
1.1464  -0.0186 -2.4029 -1.2364 0];

[a,f] = smaller(d2, 0);

function [e,next] = smaller(d, level)
    [Rows,~] = size(d);
    level = level + 1;
    for i = 1 : Rows
        d_s = d;
        d_s(i,:) = [];
        d_s(:,i) = [];
        e(i,1) = s2a(eig(d_s));
        if nnz(d_s) > 11
            [next(:,i)] = smaller(d_s, level);
            end
        end
    end
    
function f = s2a(u)
    Rows = size(u);
    f = 0;
    for i = 1 : Rows
        f = f + u(i)*u(i);
        end
    end

所有较小的 5x5 矩阵的结果 are:a

-31.6632098200000
-56.5056698200000
-22.7225231200000
-53.4562986200000
-56.3222738200000

对于所有较小的4x4:f

-17.3266712400000   -17.3266712400000   -6.02413552000000   -22.9183217200000   -17.0572911600000
-6.02413552000000   -17.0413075200000   -17.0413075200000   -39.3713837200000   -39.2719771600000
-22.9183217200000   -39.3713837200000   -5.34360784000000   -5.34360784000000   -17.0359953600000
-17.0572911600000   -39.2719771600000   -17.0359953600000   -39.2792839600000   -39.2792839600000

我想要所有较小矩阵的所有结果,以及组织它们的方法。

所以我最终在提取数据后离开了组织:

function [e] = smaller(d)
    [Rows, ~] = size(d);
    e(1, 1) = 0;
    for i = 1 : Rows
        d_s = d;
        d_s(i,:) = [];
        d_s(:,i) = [];
        e(end+1, 1) = s2a(eig(d_s));
        if nnz(d_s) > 2
            [next] = smaller(d_s);
            [rows2, ~] = size(next);
                e(end+1:end+rows2, 1) = next;
            end
        end
    end

这些是值,有一天我会重新排列它们:

value       nr of rows/cols deleted
-31.6632    1

-17.3266    2

-3.05736    3
-11.5478    3
-2.72144    3
-6.02413    2
...........

我想到了 this 其他更快的方法:

S=dec2bin(1:2^size(d1,1)-1)=='1';
b=cell(size(S,1),1);
for ix=1:size(S,1)
    b{ix}=d1(find(S(ix,:)),find(S(ix,:)));
    if isempty(b{ix})<1
        e(ix,1)=s2a(eig(b{ix}));
        end
    end