Vector where elements equals previous elements + 1
조회 수: 1 (최근 30일)
이전 댓글 표시
I wish to make a column vector where ecah element eqaul the previous element + 1. I also want to be able to decide by a loop how mane elements the vector should contain. Example: start =1;end=1 should give the vector [1}. start=1;end=3 should give the vector [1 2 3]. I hope someone has an idea about how to solve this.
댓글 수: 1
Daniel Shub
2013년 8월 14일
This is such a basic thing that I would really suggest you having another read of the manual.
채택된 답변
Andrei Bobrov
2013년 8월 14일
do as wrote Daniel
OR
end1 = 3;
for jj = end1:-1:1
vector(jj) = jj;
end
댓글 수: 2
Daniel Shub
2013년 8월 14일
I am not convinced Karl will be able to figure out make that go from A to B ...
추가 답변 (2개)
Daniel Shub
2013년 8월 14일
Using end is a bad choice since it is special in MATLAB. I think what you are asking for is
a:b
Azzi Abdelmalek
2013년 8월 14일
a=[1 1 1)
out=cumsum(a)
댓글 수: 4
Daniel Shub
2013년 8월 14일
Ahh now I see. I can see how the description would lead you to think CUMSUM is the right answer.
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!