为什么我的八度音码没有运行,没有显示错误

时间:2016-06-14 12:06:51

标签: debugging octave

我是octave的新手,我写了这段代码。但即便是第一行的fprintf声明也没有打印出来。有人请帮忙

我打字

C = strassen(zeros(1024, 1024), zeros(1024, 1024)

但是没有打印任何内容和

这个词

八度音阶2:>在给出命令

后,不会出现在下一行
function [C] = strassen(A, B)
fprintf('strassen called\n');

row = size(A, 1);%Incase zeros must be padded to make dimensions even
column = size(B, 2);
common = size(A, 2);

if row*common*column <= 1000000,%Base case when less than 10^6 multiplications needed
    C = zeros( row, column );
    for x = 1 : row,
        for y = 1 : column,
            for z = 1 : common,
                C(x, y) += A(x, z)*B(z, y);
            end;
        end;
    end;
else
    %Padding zeros if needed
    if rem(row, 2) == 1,
        A = [A; zeros(1, common)];
    end;
    if rem(column, 2) == 1,
        B = [B zeros(common, 1)];
    end;
    if rem(common, 2) == 1,
        A = [A zeros(size(A, 1), 1)];
        B = [B; zeros(1, size(B, 2))];
    end;

    m = size(A, 1);
    n = size(A, 2);
    o = size(B, 2);

    A11 = A(1:m/2, 1:n/2 );
    A12 = A(1:m/2, n/2+1: n);
    A21 = A(m/2+1 :m, 1:n/2);
    A22 = A(m/2+1 :m ,n/2+1: n);

    B11 = A(1:n/2, 1:o/2 );
    B12 = A(1:n/2, o/2+1: o);
    B21 = A(n/2+1 :n, 1:o/2);
    B22 = A(n/2+1 :n, o/2+1: o);

    M1 = strassen(A11 + A22, B11 + B22);
    M2 = strassen(A21 + A22, B11);
    M3 = strassen(A11, B12 - B22);
    M4 = strassen(A22, B21 - B11);
    M5 = strassen(A11 + A12, B22);
    M6 = strassen(A21 - A11, B11 + B12);
    M7 = strassen(A12 - A22, B21 + B22);

    %C11 = M1 + M4 - M5 + M7;
    %C12 = M3 + M5;
    %C21 = M2 + M4;
    %C22 = M1 + M3 - M2 + M6; 
    %C = [C11 C12; C21 C22];
    %C = C(1:row, 1:column);
    C = [(M1 + M4 - M5 + M7) (M3 + M5);(M2 + M4) (M1 + M3 - M2 + M6)](1:row, 1:column);
  end;
end;    

1 个答案:

答案 0 :(得分:0)

正如丹所说,有一个&#34;)&#34;你的电话里丢失了。但这可能是复制和粘贴错误。如果你使用

C = strassen(zeros(1024, 1024), zeros(1024, 1024));

你没有看到&#34; strassen叫&#34;因为计算需要很长时间。我没有等到它完成并在30秒后中止。如果你想看到递归调用,你可以刷新标准输出:

...
fprintf('strassen called\n');
fflush (stdout);
...

或使用more off禁用寻呼机。在这种情况下,您将看到

>> C = strassen(zeros(1024, 1024), zeros(1024, 1024));
strassen called
strassen called
strassen called
strassen called
strassen called

我认为你的期望是什么。