I want to create an array of length Ns(Ns+1)
and I need the first Ns
elements to be 0
, the next Ns
elements to be 1
, ...
, the last Ns
to be Ns
.
I am well aware that there are plenty of ways to do this with for-loops
, which I want to avoid for this particular task. I am looking for a way to do this using matlab functions and notions of vectorization.
For example, I had a similar array that I wanted to populate with 0, 1, 2, ..., Ns, 0, 1, 2, ..., Ns, 0, 1, 2, ...
and I accomplished that with
my_array = repmat(0:Ns, 1, Ns+1);
Is there a similar approach to be taken to achieve my purpose?
One thing I thought I could do would be to create a matrix like
0 0 0 ... 0
1 1 1 ... 1
... ... ...
Ns Ns .. Ns
and then concatenating the lines; I would know how to create the matrix but not how to concatenate the lines into an array.
Are there any other ways? Suggestions of commands are also acceptable!
Thanks.