Fill a vector based on another vector
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
Thank you in advance for your help.
0 Commenti
Risposte (1)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!