how to make a vector of 30 rows 1 column with increasing values of elements

I want to make a matrix of 30 rows 1 column like [1;1;1;1;1;2;2;2;2;2;3;3;3;3;3;4;4;4;4;4;5;5;5;5;5;6;6;6;6;6] please anyone help.

 採用された回答

Star Strider
Star Strider 2014 年 6 月 23 日
編集済み: Star Strider 2014 年 6 月 23 日
This works:
V1 = 1:6;
M = repmat(V1', 1, 5)';
V2 = M(:) % Output Vector

7 件のコメント

Zishan
Zishan 2014 年 6 月 23 日
dear this code is not working
Zishan
Zishan 2014 年 6 月 23 日
its working. thanx alot dear :)
Star Strider
Star Strider 2014 年 6 月 23 日
It does now. I renamed V to V1 after I wrote it, but forgot to update the reference to V1 in the repmat call when I copied it to post it.
Star Strider
Star Strider 2014 年 6 月 23 日
My pleasure!
Zishan
Zishan 2014 年 6 月 23 日
Dear if i want to make vector of 12 rows and 1 column suppose this vector [1;1;1;1;2;2;2;2;2;2;3;3] please tell me code for this.
Zishan
Zishan 2014 年 6 月 23 日
please tell me a general code I have to make a larger matrix of almost 3 thousand rows.
I do not see a pattern in:
[1;1;1;1;2;2;2;2;2;2;3;3]
so I do not know what to suggest as to how to generate it. If it is random in the length of each value, use the randi function to determine the number of each integer:
Vlen = 10;
V1 = 1:Vlen;
V2 = [];
for k1 = 1:Vlen
V2 = [V2; k1; repmat(k1, randi(9), 1)];
end
Change Vlen to create the approximate length of the vector you want. If you overshoot, simply truncate it to the length you need.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2014 年 6 月 23 日

コメント済み:

2014 年 6 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by