Vector where elements equals previous elements + 1
古いコメントを表示
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.
採用された回答
その他の回答 (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
3 件のコメント
Karl
2013 年 8 月 14 日
Azzi Abdelmalek
2013 年 8 月 14 日
Why this is different from Daniel's answer?
n=5
a=1
b=n
out=a:b
Karl
2013 年 8 月 15 日
Azzi Abdelmalek
2013 年 8 月 14 日
a=[1 1 1)
out=cumsum(a)
4 件のコメント
Karl
2013 年 8 月 14 日
Daniel Shub
2013 年 8 月 14 日
Azzi, while I agree this works, why would you go this way?
Azzi Abdelmalek
2013 年 8 月 14 日
I've just misunderstood the question
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.
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!