On 9/17/2013 10:01 PM, nathan wrote: > im trying to enter y = (sin(2*pi*t))*(sin(40*pi*t)) but it keep giving >me the error using * inner matrix dimensions must agree. can you help fix this error >
If t is a vector, which is most likely the case, then sin() will generate a vector also. The little * between the 2 vectors is matrix multiplication in Matlab.
To multiply 2 vectors or 2 matrices, the number of columns of the left one must be same as number of rows of the right one. These are called the inner dimensions of the 2 objects around the "*" (inner since they both point towards the "*")
In your case, the number of columns of the left one vector is not the same as the number of rows of the right one.
Let us assume your time 't' has 100 samples? or any value over 1.
So the left vector (which is now sin(2*pi*t)) will be one row by 100 columns (since it is a row vector).
But the right vector (the result of sin(40*pi*t)) will also have one row and 100 columns.
But "*" wants the right vector to have 100 rows to match the number of columns of the left vector, or it want the left vector to have one column to match the number of rows of the right vector, since inner dimensions must match.
But 100 is not equal to one. So it complained.
One way to fix this is to use ".*" instead of "*" only for the middle "*", like this
y = (sin(2*pi*t)) .* (sin(40*pi*t))
Now instead of matrix multiplication, element by element multiplication is done. This should fix the problem.