Here is a very simple line of code:

`x = 3;A = 1:x;for i = 1:length(A) y = repelem(A(:,i),i); Y = y(1,:)end`

I want to generate result in the form

`[1 2 2 3 3 3]`

What I am doing mistake, please help me in this regard. Thanks

Skip to content# MATLAB: How to combine the result of for loop

###### Related Question

arrayfor loopiteration

Here is a very simple line of code:

`x = 3;A = 1:x;for i = 1:length(A) y = repelem(A(:,i),i); Y = y(1,:)end`

I want to generate result in the form

`[1 2 2 3 3 3]`

What I am doing mistake, please help me in this regard. Thanks

- Distance between all points of two vectors
- From a=[1 2 3 4] to b=[1 1 2 2 3 3 4 4]
- I want to apply a for loop to an array (say [1 2 3]) so that the output gives every possible combination of that array (i.e. [123], [132], [213], [231], [312], [321])
- Using repelem without prior knowledge of the number of matrix dimensions
- How to make a colum of multiple 1 to 5. i want to make column vector of [1;1;1;1;1;1;1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;3;3;3;3;3;3;3;3;3;3;3;3]. is there any way to make this kind of vector instead of typing this many times.
- How to resize or scale up a matrix without for loop
- Place polyfit values in a matrix using a loop
- Size of matrix keeps changing even after pre-allocating
- How Can I replace the following for loop by vectorization

## Best Answer