如何在MATLAB中为此代码删除四个嵌套的“ for”循环。有什么建议么?

时间:2018-10-12 05:43:15

标签: matlab loops for-loop nested

当(u,v)和(x,y)的矩阵维数超过(200,200)时,代码将非常缓慢地工作。为了简单起见,我认为两者均为(3 * 3)

x1=1;y1=1;u1=1;v1=1;

        for u = -1:1:1
             for v = -1:1:1

                for x = -1:1:1
                  for y = -1:1:1

                    value(x1,y1) = exp( ( -1i*(((u-x)^2) + (v-y)^2))
                    y1 = y1+1;
                  end
                   x1 = x1+1;
                   y1 = 1;
                end
            S_rows = sum(value,2); %Adding components of matrix "value"
            S_complete = sum(S_rows);
            E2(u1,v1) = S_complete; 
                 x1 = 1;
                 v1 = v1 + 1;
              end
                u1 = u1+1;
                v1 = 1;
         end

0 个答案:

没有答案