How do I generate a vector of ordered integer

I want to generate a vector of the form [1 2 3 1 2 3 4 5 1 2 3 4 5 6 7 1 2 3 4 5 6 7 9] with simple matlab code.

 採用された回答

the cyclist
the cyclist 2015 年 11 月 21 日
編集済み: the cyclist 2015 年 11 月 21 日

0 投票

One way:
x = [1 2 3 1 2 3 4 5 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 9];
But I'm guessing that's not what you meant.
Another way:
x = [];
for k = 3:2:9
x = [x, 1:k]
end
In general, it is not a good idea to "grow" a vector like this, by simply appending. It's better to define the vector length ahead of time, preallocating the memory. But, I'm feeling lazy right now.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Coder についてさらに検索

質問済み:

2015 年 11 月 21 日

編集済み:

2015 年 11 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by