Help in MATLAB, plotting a signal

  • MATLAB
  • Thread starter Az83
  • Start date
  • #1
8
0

Main Question or Discussion Point

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

t=1:1:100;
s= 2*sin(2*pi*.05*t)*5*sin(2*pi*2*t)+.75*randn;
plot(t,s)


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?
 

Answers and Replies

  • #2
rbj
2,226
7
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:
  • #3
8
0
That worked perfectly. Thanks so much for the help and quick reply :-)
 

Related Threads for: Help in MATLAB, plotting a signal

  • Last Post
Replies
2
Views
6K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
0
Views
1K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
3
Views
8K
Replies
1
Views
2K
Replies
6
Views
5K
  • Last Post
Replies
1
Views
4K
Top