how to make a vector of 30 rows 1 column with increasing values of elements
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
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.
Accepted Answer
Star Strider
on 23 Jun 2014
Edited: Star Strider
on 23 Jun 2014
This works:
V1 = 1:6;
M = repmat(V1', 1, 5)';
V2 = M(:) % Output Vector
7 Comments
Zishan
on 23 Jun 2014
dear this code is not working
Zishan
on 23 Jun 2014
its working. thanx alot dear :)
Star Strider
on 23 Jun 2014
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
on 23 Jun 2014
My pleasure!
Zishan
on 23 Jun 2014
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
on 23 Jun 2014
please tell me a general code I have to make a larger matrix of almost 3 thousand rows.
Star Strider
on 26 Jun 2014
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.
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)