Problem 1035. Generate a vector like 1,2,2,3,3,3,4,4,4,4
Solution Stats
Problem Comments
-
28 Comments
With the usage of for loops this becomes doable. There are similar problems where it (and while) are explicitly banned in test cases so that my solution there got errored. How do I solve this without?
@Long Runjia Yu Perhaps look at other (correct) solutions to this problem, and learn from them.
Here (and elsewhere) one way to solve the problem at hand is to generate more than you need, and then throw away that which is superfluous (both without loops).
Very interesting
Solution Comments
Show commentsProblem Recent Solvers12175
Suggested Problems
-
Back to basics 21 - Matrix replicating
1646 Solvers
-
Sum of diagonal of a square matrix
1592 Solvers
-
Given a matrix, swap the 2nd & 3rd columns
1148 Solvers
-
576 Solvers
-
Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.
942 Solvers
More from this Author17
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!