Insert values of one vector at specific places into another

4 visualizzazioni (ultimi 30 giorni)
Hello MATLAB-Community,
I'm stuck with the following problem:
If got two vectors, a and b.
a = [0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 1 0];
b = [ 10 20 30 40 50 ]
Can somebody give ma a hint, how I best merge these two into
c=[0 0 0 0 10 0 0 0 20 0 30 0 0 0 40 0 0 50 0]
Thank you in advance for your help!
Christian

Risposta accettata

Turlough Hughes
Turlough Hughes il 24 Ago 2021
a = [0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 1 0];
b = [ 10 20 30 40 50 ];
c = zeros(size(a));
c(logical(a)) = b
c = 1×19
0 0 0 0 10 0 0 0 20 0 30 0 0 0 40 0 0 50 0

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by