How can I create a linspace with a condition

1 vue (au cours des 30 derniers jours)
Rasmus Nordström
Rasmus Nordström le 25 Fév 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?

Réponse acceptée

Stephan
Stephan le 25 Fév 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
  1 commentaire
Rasmus Nordström
Rasmus Nordström le 25 Fév 2019
Yes, now i feel stupid. Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by