フィルターのクリア

Insert values of one vector at specific places into another

1 回表示 (過去 30 日間)
Christian S.
Christian S. 2021 年 8 月 24 日
コメント済み: Christian S. 2021 年 8 月 24 日
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

採用された回答

Turlough Hughes
Turlough Hughes 2021 年 8 月 24 日
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
  1 件のコメント
Christian S.
Christian S. 2021 年 8 月 24 日
Wow, that was quick. Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by