How can I create a linspace with a condition
조회 수: 1 (최근 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!