在scilab中制作3D矩阵平均器?

时间:2013-12-19 20:03:59

标签: matlab math matrix average scilab

我正在制作一个scilab程序来平均立方体中的3d矩阵。这大部分已经完成,但我想将大小设置为给定的总和,(每个立方体中的体素都加起来设定量)和每次我尝试添加此功能时,我都会一直违反该程序。

function totSAR = comptS(Material, SAR, a, b, c, a1, b1, c1, grams)

si=size(SAR);
radius=0;
OK=0;
totwei=0;
totSAR=0;
totpx=0;
while (totwei<=grams*1e-3 && OK==0)
    totwei2=totwei;
    totSAR2=totSAR;
    totpx2=totpx;
    totwei=0;
    totpx=0;
    totSAR1=0;
    totSAR=0;
    radius=radius+1;
    for o=-radius:radius
    rado=floor(sqrt(radius^2-o^2));
        for m=-rado:rado
            radm=floor(sqrt(rado^2-m^2));
            for n=-radm:radm
                if (a+m >= 1 && a+m <= si(1) && b+n >=1 && b+n <=si(2) && c+o >= 1 && c+o <si(3))
                if totwei<=10e-3
                    totwei=totwei+a1*b1*c1*Material(a+m, b+n, c+o);
                        if SAR(a+m, b+n, c+o)>0
                    totpx=totpx+1;
                        totSAR=totSAR+SAR(a+m, b+n, c+o);
                end
            end
            end
        end
    end
end
if totSAR==totSAR1
    OK=1;
end
end

coefw = (grams*1e-3 - totwei2)/(totwei-totwei2);
totpxs = coefw*(totpx-totpx2);
totSARs = coefw*(totSAR-totSAR2);

totpx;
if totpx>0
totSAR=(totSAR2+totSARs)/(totpx2+totpxs);
end
end

对不起,我是一个新手,谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

您唯一的问题是,在创建体素时,您无法更新totwei变量。您需要从剩余的所需重量中减去体素的值,并将其添加到总体中重量。

totwei = totwei + voxel
valleft = valleft - voxel