필터 지우기
필터 지우기

Multiply x sequentially with items of a vector

조회 수: 1 (최근 30일)
Christoph Meier
Christoph Meier 2015년 8월 7일
댓글: Torsten 2015년 8월 7일
Dear MATLAB community,
I would like to construct an index, which should start with 100. I have computed a vector, which then determines the change in the index in each time period. For example, for 4 time periods:[1.1,1.2,1.3,1.4] Basically, the operation should compute and produce the following vector:
  1. 100*1.1
  2. (100*1.1)*1.2
  3. ((100*1.1)*1.2)*1.3
  4. (((100*1.1)*1.2)*1.3)*1.4
Thank you very much in advance! I appreciate any help, as I am still a beginner with MATLAB.

채택된 답변

Torsten
Torsten 2015년 8월 7일
편집: Torsten 2015년 8월 7일
vder(1)=v(1);
for l=2:length(v)
vder(l)=vder(l-1)*v(l);
end
vder=100*vder;
v is the original vector, vder is the vector you are looking for.
Best wishes
Torsten.
  댓글 수: 2
Stephen23
Stephen23 2015년 8월 7일
편집: Stephen23 2015년 8월 7일
See Walter Roberson's answer for the simpler and faster way to do this.
Torsten
Torsten 2015년 8월 7일
And cumprod.m works without a loop ?
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 7일
편집: Stephen23 2015년 8월 7일
cumprod([100, 1.1, 1.2, 1.3, 1.4])

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by