How to fill a vector with values and plot?

4 views (last 30 days)
Andre589
Andre589 on 31 Mar 2017
Commented: Rik on 31 Mar 2017
Hello everyone
I am realtive new in MatLab and got a question for plotting a vector.
So I have the function 1/x sin²(x)
I need to create a vector with values from 1 to 10 in 0.25 steps
So I created the vector like this
y=[1:0.2:10]
Now I need to fill the vector with values from x so basically I use the values from y e.g. 0.25 and put in in the function.
How can I do this in MatLab?
And the last step is to plot the function for plotting I need to create a time vector e.g.
t[-5:0.25:5]
plot (y,t)
Does this look right?
Thanks for your help !
  1 Comment
Rik
Rik on 31 Mar 2017
It sounds like you would really benefit from one of the many tutorials on how to get started with Matlab. I'll give you the answer, but this is one of the first things you will learn with such a tutorial.
t=-5:0.25:5;
y=1/(t.*sin(t).^2);%use .* and .^ for element-wise product and power
plot(t,y)

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!