MATLAB: Error : Inner matrix dimensions must agree.

agreedimensinoserrorinnermatrixmust

I'm getting an Error saying Inner matrix dimension must agree while trying to multipicate and plot
X = 2*cos(2*f1*pi*t)+sin(2*f2*pi*t)
Y = Ac*cos(Fc*2*pi*t)
Z = X*Y
I don't understand why i'm getting this error
Note : All the variables are defined in the code .

Best Answer

  • You forgot to give the actual error message! So we don't know which line it bombed on.
    I agree with Adam and Alex though. Try .* and if that doesn't work, examine the sizes of all the variables. Of course you know that with a matrix multiplication with X*Y and X is rowsx*colsx and Y is rowsy * colsy, you must have colsx equal rowsy. For example [5*3] * [15*20] won't work but [5*3] * [3 * 20] will work because the inner dimensions are the same (unlike in your case).
    Another thing to check is the shape. For example if X is a row vector and Y is a column vector (or vice versa) then multiplying them will not give a vector, even if they're the same length. Due to automatic expansion it will give a rectangular matrix.