How can i use linspace with different intervals?

3 visualizaciones (últimos 30 días)
Mahrosh
Mahrosh el 8 de Mayo de 2020
Comentada: Rik el 9 de Mayo de 2020
The value for x is 0 to 1. I want to use 0 to 0.9 with interval 0.01 and 0.9 to 1 with interval 0.99.
I used linspcae like this but this is giving me an error.
x = linspace(0,0.9,91;0.9,1,91);
How can i use different interval in linspace? Any idea?

Respuesta aceptada

Rik
Rik el 8 de Mayo de 2020
You will have to call linspace multiple times:
part1=linspace(0,0.9,91);
part2=linspace(0.9,1,91);
x = [part1,part2(2:end)];
  1 comentario
Mahrosh
Mahrosh el 8 de Mayo de 2020
Editada: Mahrosh el 8 de Mayo de 2020
thanks for your comments.

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord
Steven Lord el 8 de Mayo de 2020
If you know both endpoints and the interval, linspace isn't the best tool for the job. The colon operator (:) is.
x = 0:0.1:0.9;
Rik's suggestion of creating each piece independently and combining them afterwards, but use colon instead of linspace.
  5 comentarios
Mahrosh
Mahrosh el 8 de Mayo de 2020
Thankyou steven for further explanation. I want to ask there is any effect on my calculation If I used number in decimal instead of intergers?
Rik
Rik el 9 de Mayo de 2020
There isn't any difference in the result, only in how you read the code as a human.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by