필터 지우기
필터 지우기

repeat a vector with a pattern

조회 수: 1 (최근 30일)
Jeong Ho
Jeong Ho 2015년 7월 7일
편집: Azzi Abdelmalek 2015년 7월 7일
I have a vector v=[1 2] and another vector (1 x n) k (e.g., [1 7 9]). I want to create a new vector,
[v+2*k(1) v+2*k(2) ... v+2*k(n)]
In the example, it would be [3 4 15 16 19 20].
How do I do this in matlab? I'd appreciate your help. Thank you very much in advance!
Best, John

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 7일
편집: Azzi Abdelmalek 2015년 7월 7일
v=[1 2]
k=[1 7 9]
out=cell2mat(arrayfun(@(x) v+2*x,k,'un',0))
or
out=reshape(bsxfun(@plus,v',2*k),1,[])

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by