# Sketching Sine Wave in Matlab

I am working with matlab in college and I need to generate sine wave whcih represents signal going through a wire.

But its not clear to me what t equals to and how can I multiply $y$ by $t$

this is the formula

$$y(t) = 1.2\sin(35.000\pi t+2.15\text{ rads})$$

This is my Matlab code

time = 1:1.0:10;
y = y*time
plot(y)


It gives me error when I want to multiply y*time

Anyone know where to go from here?

• You get the error because you are doing an array multiply. That whole command is unnecessary and wrong in any case. "t" is time. Your command should be 1.2*sin(35 * pi * time + 2.15) Nov 19, 2014 at 18:20
• In Matlab, trig function use radians as inputs -- sin(pi/2)=1. You don't need to (or want to) convert radians to degrees Nov 19, 2014 at 18:28
• why are you doing y=y*time? Nov 19, 2014 at 18:29
• You need finer timesteps if you want to be able to see the 'real' sine waveform. Otherwise you get aliasing.
– mng
Nov 19, 2014 at 18:42
• what time should equal to see the real sine waveform? and to avoid that aliasing? Nov 19, 2014 at 18:45

>> time= 1:1:10;
>> y= 1.2*sin(35*pi*time+2.15);
>> plot(time, y); • For OP's benefit it's worth noticing that this plot is severely aliased. Nov 19, 2014 at 18:58

More reasonably

time = 0:0.00001:1.0;

y= 1.2*sin(35*pi*time+2.15);

plot(time, y) • Most certainly -- but I'd suggest that your sample rate is overkill -- huge arrays, and it would make any filtering in the bandwidth of interest be fairly difficult. Nov 20, 2014 at 0:03

You have many replies as to what is the correct matlab code (see mine below) - note: with a frequency of 17.5Hz, you need a timestep of at least 10-100 time this to reproduce is clearly (

t = 0:0.001:10;
y = 1.2 * sin(35.000*pi*t + 2.15);
plot(t,y) to add some insight into the the matlab error that you would have experienced at this step

y = y*time

Error using  *
Incorrect dimensions for matrix multiplication. Check that the number of columns in
the first matrix matches the number of rows in the second matrix. To perform
elementwise multiplication, use '.*'.


for starters there is no need todo time*y as y is already a function of time. The error however is due to time being a 1x10 matrix and y is a 1x10 matrix.

By default "*" will attempt to perform matrix multiplication when both operands are matrix's. You cannot perform matrix multiplication on [1 x 10] by [1 x 10]. You can on [1 x 10][10 x 1] but that is nonsensical for this.

IF you did want to multiple two arrays together and they are [1 x n] then you can use the scalar operator

y.*time

which would produce a [1 x 10] matrix which is the result of an element by element multiplication.

HOWEVER, this isn't what you want so please review the multiple correct implementations shown here. You also missed the phase shift component (2.15) in your original question. NOTE: trig functions by default operate in radians

An easier way to do this is to use the fplot function. The code would look something like this:

syms time;
y = 1.2*sin(35*pi*time+2.15);
fplot(y, [0 10])

This is what you end up getting for the waveform using this process. 