Help in MATLAB, plotting a signal

Click For Summary
SUMMARY

The discussion centers on resolving a MATLAB error related to matrix dimensions during signal plotting. The user initially encountered an "Inner matrix dimensions must agree" error due to incorrect use of the multiplication operator. The solution involves using the element-wise multiplication operator ".*" to correctly compute the signal. The corrected code is: s = (2*sin(2*pi*.05*t)) .* (5*sin(2*pi*2*t)) + .75*randn(size(t));, which successfully plots the signal.

PREREQUISITES
  • Basic understanding of MATLAB syntax and operations
  • Familiarity with matrix and element-wise operations in MATLAB
  • Knowledge of signal processing concepts
  • Experience with plotting functions in MATLAB
NEXT STEPS
  • Explore MATLAB's element-wise operators, specifically ".*" and ".^"
  • Learn about MATLAB's plotting functions and customization options
  • Investigate signal processing techniques in MATLAB
  • Review MATLAB documentation on matrix dimensions and operations
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly beginners and those interested in signal processing, who are looking to troubleshoot common plotting errors and enhance their coding skills in MATLAB.

Az83
Messages
7
Reaction score
0
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?
 
Physics news on Phys.org
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:
That worked perfectly. Thanks so much for the help and quick reply :-)
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K