Problem 1035. Generate a vector like 1,2,2,3,3,3,4,4,4,4
function ans = GenerateVector(n)
ans = 1;
for n = 2:n
ans = [ans n*ones(1, n)];
could sb explain me why this code is flagged a as a bad one ?? it works !! and another thign in problem definition it is not clearly stated that the solutions must be straight code without writing a function. I wrote a function and it works well to the definition of the problem. then I am getting incorrect information after submission. dear cody team: please write more specific requirements of the problem. you will miss many misunderstandings then.
Your function has to use exactly the same name that is provided in the function template. In this case, the function must be called "you_fcn_name". You wrote a function called "GenerateVector". Change the name of your function and it should pass.
The test suite has been expanded.
Is there any way to avoid the for loop? I really want to but I don't see how right now.
Good one! took some time but finally did it.
Can it be done without a for loop?
use command "repelem"
great problem. Interesting for beginners like me.
can we do it without loops?
Incredibly fun problem!
Easy and funny
Great and funny
looks tricky but easy to solve.
oh yeah, it's all coming together
Solution CommentsShow comments
Problem Recent Solvers8738
Make the vector [1 2 3 4 5 6 7 8 9 10]
Basics: 'Find the eigenvalues of given matrix
More from this Author17
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!