Vector 0 to 2pi with 1000 point equal spacing

132 views (last 30 days)
Marcel
Marcel on 26 Apr 2014
Commented: Vaibhav on 27 Jun 2023
Hi,
it might be trivial but I struggle to create a vector that contrains 1000 points equally spaced between 0 and 2pi.
any help will be appreciated!

Answers (3)

Azzi Abdelmalek
Azzi Abdelmalek on 26 Apr 2014
linspace(0,2*pi,1000)
  2 Comments
Walter Roberson
Walter Roberson on 21 Sep 2017
Be careful, though: the spacing between the items above will not be 2*pi/1000, it will be 2*pi/999 .
When you talk about a particular number of points "between" a range, you have to think carefully about whether one endpoint or both endpoints or neither endpoints is included in that particular number.
linspace(0,2*pi,1000) would not be appropriate for 1000 Hz: 1000 Hz would be linspace(0,2*pi,1001), because for a sine or cosine wave, 0 and 2*pi overlap, like counting the same point twice.
If you want one full cycle exactly then,
t = linspace(0, 2*pi, 1001); %generate 1000 points _before_ the endpoint
t(end) = []; %throw away the endpoint
Vaibhav
Vaibhav on 27 Jun 2023
thank you sir for helping us ..........

Sign in to comment.


Jan
Jan on 27 Apr 2014
When I ask my favorite internet search engine for the terms "matlab vector equally spaced", I get a link to the documentation of linspace as first hit. Of course, this forum is smart also, Google took 0.35 seconds only for this answer. I'm afraid we cannot beat this speed. :-)
  6 Comments
Walter Roberson
Walter Roberson on 21 Sep 2017
Alison Haire: Jan linked to linspace(), which is the appropriate routine for this purpose.
Jan
Jan on 21 Sep 2017
Edited: Jan on 28 Jun 2018
@Alison: "Arrogance"? I'm less emotional when posting answers than you assume. I've posted the link to the solution linspace and explained, how such problems can be solved much more efficiently than waiting for the forum to answer. The idea behind it is not to solve only this problem, but allowing for more efficient solutions in the future also.
When I take the relevant words from the title: "Matlab Vector equal spacing" or from the body: "Matlab points equally spaced", Google finds the link to linspace as first hit. It is hard here, not to find matching terms for a search.
Alison, note that we find many questions every day in this forum, which could be solved in few seconds by searching in the net or in the forum at first. Perhaps I've posted about 2000 or 3000 answers, which could have been found by the OP by investing a tiny bit of time with searching at first. And this does not concern only me, but all of the frequent contributors. Many users do not show any own effort, but try to forward the required work to others in the forum. With this background, I ask you to read my answer again: I've simply explained, how I would find the solution of the problem, included a link and admitted, that Google is unfortunately more efficient than the forum (include my person). Finally I added a smiley. Now you confuse this with "Google it by your own, you idiot". Sigh. I'm not here to make the other members happy, but only to solve Matlab problems.

Sign in to comment.


maryam Haider
maryam Haider on 16 Jul 2022
t=linspace(0,2*pi,1000)

Tags

Community Treasure Hunt

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

Start Hunting!