Error using ==> times Matrix dimensions must agree

조회 수: 9 (최근 30일)
Sumiran Dhamaskar
Sumiran Dhamaskar 2017년 10월 19일
답변: Cam Salzberger 2017년 10월 19일
I currently doing a audio compression project I am having some issues regarding my matrix. Getting an error Error using ==> times Matrix dimensions must agree
[b,R] = wavread ('transparent-build-up.wav');
N = length(b);
c = dct(b); % Compute the interpolation model coefficients
w = sqrt(2/N);
f = linspace(0,R/2,N)';
plot (f,w*c); % Shows a plot of the frequencies coefficients for the sample
% Generate a mask of zeros and ones. m is 0 for every frequency above 3000, 1 otherwise.
% This mask will cut-off all frequencies above 3000 cycles/second.
m = (f<3000);
plot (f,(w*m.*c)); % Display the filtered frequency coefficients.
%y = idct(m.*c); % Generate a filtered sound sample data set
sound(y,R); % Listen to the result
  댓글 수: 1
Rik
Rik 2017년 10월 19일
What are the sizes involved for (w*m.*c)? c might not be 1xN or Nx1.
Next time, make sure to copy the entire error message. That will make it much easier to debug. That's the whole point of having a verbose error message.

댓글을 달려면 로그인하십시오.

답변 (1개)

Cam Salzberger
Cam Salzberger 2017년 10월 19일
Hello Sumiran,
Rik's on the right track. I'm fairly certain that wavread will give you a row vector (1xN) for the first output ("b"), which will then cause "c" to have that same size. "w" is a scalar, so w*m will have the size of "m", which is a column vector due to the transpose in the definition for "f". (Nx1).*(1xN) will result in that error, so you probably want to skip the transpose, or transpose b when you first get it.
Also, it may help readability if your variables had meaningful names.
Hope this helps!
-Cam

카테고리

Help CenterFile Exchange에서 Digital Filter Design에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by