How can I create a linspace with a condition
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Stephan
2019 年 2 月 25 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!