Message Boards Message Boards

0
|
23023 Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Use a Wolfram Language equivalent to Matlab's "linspace" function?

Posted 5 years ago
POSTED BY: Ehud Behar
4 Replies
Posted 2 years ago

You can also do

Array[f,n,{a,b}]

to generate a list of length n with elements f[i] with values from a to b.

For example

Array[Sin[2 \[Pi] 440 #] &, 100, {0, 1}]
POSTED BY: Ehud Behar
Posted 5 years ago

Thanks very much!

POSTED BY: Ehud Behar
Posted 5 years ago

I think what you want is Subdivide, which I believe is similar to linspace, however instead of n evenly spaced points, Subdivide generates the list of valued from subdividing the range into n equal parts. So linspace(-5,5,7) from Matlab would be equivalently N@Subdivide[-5, 5, 6] in Mathematica:

In[4]:= N@Subdivide[-5, 5, 6]
Out[4]= {-5., -3.33333, -1.66667, 0., 1.66667, 3.33333, 5.}

Note that I am not a Matlab user and haven't actually used linspace, this is just based on what I was able to infer from their documentation.

POSTED BY: Kyle Martin

use:

Subdivide
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract