Insert values of one vector at specific places into another

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Turlough Hughes
Turlough Hughes am 24 Aug. 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

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by