0
votes

When dealing with the following code I get Matrix error must agree error. E(m+1)=z/w; The workspace though clearly indicates that the dimensions are the same for both z and 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;

any help would be much appreciated, thanks!

1

1 Answers

0
votes

You can create an "array of matrices" by storing them in a 3D matrix:

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