## Fill a vector based on another vector

### Pilar Jiménez (view profile)

on 21 Oct 2019
Latest activity Edited by Pilar Jiménez

### Pilar Jiménez (view profile)

on 21 Oct 2019
I know the title is somewhat confusing, but I hope you can help me. I need to make a code for a specific application, I am confused on how to do a part. I have the following:
Nmax=25;
A=ones(1:Nmax);
B=[1;1;6;12,1,2,5,2];
What I need to do is fill vector A with the number of zeros indicated by vector B, that is, vector A changes from ones to zeros based on vector B in the order in which it is found. For example:
The first and second values of B indicate that it is 1 zero, therefore, vector A = [00111 ...]
The third value of B indicates that there are 6 zeros, therefore, vector A = [0000000011111 ...]
And so on.
If the number of zeros exceeds the value of Nmax, save it in another vector and cut the count to the integers of B.
The logic of the code should be like this, I was already trying index by index with a for cycle, but it makes errors.

### Yuan Li (view profile)

on 21 Oct 2019

A(1:sum(B(:))) = 0;