【问题标题】:Matlab error Matrix dimensions must agreeMatlab错误矩阵尺寸必须一致
【发布时间】:2016-02-25 22:25:36
【问题描述】:

在处理以下代码时,我得到 Matrix 错误必须同意错误。 E(m+1)=z/w; 工作区虽然清楚地表明 z 和 w 的尺寸是相同的,1001x1001。

   l=[0:10000];
n=[0:1000];
g=1;
a=-0.5;
b=0.9;
for m=l
    xl=cos(2*pi*m*n/10000)';
    yl=ex22_1(xl,g,a,b);
    %multiplication of matrix with its transpose resolves SUMn(yl[n])^2
    z=yl*yl';
    w=xl*xl';
    E(m+1)=z/w;
end
printf(gcf,'-depsc2',['lti_crazy_function.eps']);
createFigure;
plot(1,10*log10(e),'.');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid on;

任何帮助将不胜感激,谢谢!

【问题讨论】:

    标签: matlab matrix dimensions mismatch


    【解决方案1】:

    您可以通过将它们存储在 3D 矩阵中来创建“矩阵数组”:

    E = zeros(1001,1001,l);  %% using the number of loops as the last dimension
    for m=1:l  %% Note: your for loop above only does one iteration; this makes it do `l` iterations (the letter L)
        xl=cos(2*pi*m*n/10000)';
        yl=ex22_1(xl,g,a,b);
        %multiplication of matrix with its transpose resolves SUMn(yl[n])^2
        z=yl*yl';
        w=xl*xl';
        E(:,:,m)=z/w;
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-11
      相关资源
      最近更新 更多