Effacer les filtres
Effacer les filtres

Insert values of one vector at specific places into another

1 vue (au cours des 30 derniers jours)
Christian S.
Christian S. le 24 Août 2021
Commenté : Christian S. le 24 Août 2021
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

Réponse acceptée

Turlough Hughes
Turlough Hughes le 24 Août 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

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by