how to create a sequence with percentage increments
조회 수: 1 (최근 30일)
이전 댓글 표시
i want to create a squence of n numbers that start at 3 and go up in 10% increments. how would i do that?
댓글 수: 0
답변 (2개)
DGM
2021년 8월 10일
편집: DGM
2021년 8월 10일
Here's one way.
n = 15;
x0 = 3;
inc = 0.1;
x = ones(1,n-1)*(1+inc);
x = cumprod([x0 x])
There are probably simpler ways with a bit of math. You could do it with a simple exponential if you just calculate the right parameter.
x2 = 0:n-1;
x2 = x0*exp(log(1+inc)*x2)
Whichever one of these three options is fastest depends on the vector length and version/environment.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!