How to use linspace and what is it's purpose?
86 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
programmingnewbie
el 4 de Jun. de 2016
Hi all,
What is the purpose of linspace?
eg linspace(2,7,100) what will happen when i type in this code?
Thanks
3 comentarios
dpb
el 4 de Jun. de 2016
Give it a go and see(*)...or, there's always
doc linspace % when in doubt
(*) altho linspace(2,7,10) may make enlightenment simpler to comprehend.
Respuesta aceptada
Star Strider
el 4 de Jun. de 2016
There are two principal ways to create vectors in MATLAB. One is the colon (:) operator, and the other is the linspace function. The principal difference is that with the colon operator, you define the interval between successive elements and let the length of the resulting vector vary, and in linspace, you define the length of the vector and the function calculates the interval to fit the length.
4 comentarios
Stephen23
el 8 de Feb. de 2020
Editada: Stephen23
el 12 de Mzo. de 2020
"is one more advantageous?"
No, they do two different things. Using two posts I mark out a distance on the ground, then I tell you:
- to walk between the posts using exactly 50 identically-sized steps. You would have figure out the distance, divide it up to find the step size (which is unknown in advance). You might need tiny steps or seven-league boots to walk the distance, but you can only take exactly 50 steps.
- to walk towards the second post taking steps of a particular length that I specify. You start walking from the first post using the step size that I gave you, and use as many steps are required, stopping when you reach the other post or cannot fit any more steps of that length. You might be able to do it with one step, or two steps, or ... 23 steps, or 1729 steps, or zero steps (unknown in advance).
Are these the same thing? No.
Jay Perks
el 10 de Mzo. de 2020
A more visual way to understand is to graph it.
x = linspace(0, 1, 20)
y = sin (2*pi*x)
plot (x, y)
You should see a sine wave.
now use the sample graph.
stem (x, y)
you should see 20 samples. Now try 50 in linspace instead of 20.
x = linspace(0, 1, 50)
y = sin (2*pi*x)
stem = (x,y)
I hope this answers your question :)
Más respuestas (0)
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!