필터 지우기
필터 지우기

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by