MATLAB: Error using .* Matrix dimensions must agree.

matrix dimension

WL = 40; % window length
mez2= 10; % threshold
Fvz = 20;
nastdelka = length(data);
figure(2);
plot(time,data);
xlabel('time [s]');
ylabel('Amplituda');
title('Pitch');
for n = 1:(nastdelka*Fvz-2*WL-1)
okno1=data(n:n+WL-1);
okno2=data(n+WL+1:n+1+2*WL-1);
m = linspace(0,WL-1, WL);
for k = 1:WL/2
Y1(k) = sum(okno1.*(exp(-2*pi*1i*k*m/WL))); <-- ERROR: Error using .* Matrix dimensions must agree.
Y2(k) = sum(okno2.*(exp(-2*pi*1i*k*m/WL)));
end
Y1=abs(Y1);
Y2=abs(Y2);
G2(n) = max (0.5*(Y1./Y2+Y2./Y1)-1);
end

Best Answer

You didn't attach the time and data variables, so I can only speculate, but it seems that okno1 is a column matrix, 'm' is a row matrix, and you are using some older version of MATLAB. Try changing these lines like this.
Y1(k) = sum(okno1.*(exp(-2*pi*1i*k*m.'/WL))); % .' is added after variable m
Y2(k) = sum(okno2.*(exp(-2*pi*1i*k*m.'/WL)));
Related Question