Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help in MATLAB, plotting a signal

  1. May 2, 2008 #1
    I'm pretty new in MATLAB, and I can't seem to get it to display a signal. I have the following:

    s= 2*sin(2*pi*.05*t)*5*sin(2*pi*2*t)+.75*randn;

    But i keeps giving me the following error:

    ??? Error using ==> mtimes
    Inner matrix dimensions must agree.

    Error in ==> signal at 5
    s= 2*sin(2*pi*.05*t)*5*sin(2*pi*2*t)+.75*randn;

    Does anyone have any suggestions?
  2. jcsd
  3. May 3, 2008 #2


    User Avatar

    one of the things about MATLAB is that the "*" symbol means matrix multiplication, but has been allowed to be used when either the left or right operand (or both) are scalers (which, in MATLAB is a 1x1 matrix, but they recognize that and assign meaning to a multiplication of that as a scaler against any matrix). but what you can't do is multiply two matrices together (bigger than the 1x1, which is dually interpreted as a scaler), unless the number of columns of the left operand is equal to the number of rows of the right. to do element-by-element multiplication of two identically sized and shaped arrays (i won't call them "matrices" here), you use the ".*" operator. sometimes you'll also need to use the ".^" operator, too, because the normal power operator "^" also has matrix meaning when one of the operands are matrices.

    oh, i forgot to correct the expression:

    s= (2*sin(2*pi*.05*t)) .* (5*sin(2*pi*2*t)) +.75*randn(size(t));

    i think that will work.
    Last edited: May 3, 2008
  4. May 3, 2008 #3
    That worked perfectly. Thanks so much for the help and quick reply :-)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook