How can I create a linspace with a condition
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Rasmus Nordström
el 25 de Feb. de 2019
Comentada: Rasmus Nordström
el 25 de Feb. de 2019
Hi
I want to create a linspace with a condition for the spacing, so that the spacing has a maximum allowed value. For example, if the spacing gets to high the function creates more points. Is this possible?
0 comentarios
Respuesta aceptada
Stephan
el 25 de Feb. de 2019
Hi,
if you know the maximum allowed spacing you can use:
function result = mySpacing(StartValue,EndValue,maxSpaceValue)
result = linspace(StartValue,EndValue,ceil((EndValue-StartValue)/maxSpaceValue+1));
end
This will ensure that the spacing is always smaller or equal to the given argument:
result1 = mySpacing(1,2,0.12)
result1 =
Columns 1 through 9
1.0000 1.1111 1.2222 1.3333 1.4444 1.5556 1.6667 1.7778 1.8889
Column 10
2.0000
result2 = mySpacing(0,2,0.15)
result2 =
Columns 1 through 9
0 0.1429 0.2857 0.4286 0.5714 0.7143 0.8571 1.0000 1.1429
Columns 10 through 15
1.2857 1.4286 1.5714 1.7143 1.8571 2.0000
result3 = mySpacing(0,2,0.5)
result3 =
0 0.5000 1.0000 1.5000 2.0000
Best regards
Stephan
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating 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!