Combining two vectors in a pattern

조회 수: 5 (최근 30일)
Robin
Robin 2019년 7월 24일
답변: Walter Roberson 2019년 7월 24일
Is there a way to combine two vector let's say
a=[1,2,3,4,5,6,7,8,9]
b=[10,20,30,40];
the resulting vector would be
result=[1,2,3,10,20,4,5,6,30,40,7,8,9];
Is it possible to do this without loops
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2019년 7월 24일
n = length(a)+length(b);
mask = ismember(mod(1:n, 5), [0 4]);
result = zeros(1, n);
result(~mask) = a;
result(mask) = b;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by