How to extend a row vector down in increasing values?

조회 수: 4 (최근 30일)
TastyPastry
TastyPastry 2016년 9월 10일
답변: Star Strider 2016년 9월 10일
Say I have the vector
a = [4 5 6];
How can I make the vector into
[4 5 6
5 6 7
6 7 8
7 8 9
...]
where each column increments by some constant amount? The number of initial values nor the number of new rows are constant.

채택된 답변

Star Strider
Star Strider 2016년 9월 10일
The bsxfun function is perfect for this:
a = [4 5 6];
N = 5; % Desired Row Lenth
Out = bsxfun(@plus, a, [0:N]')
Out =
4 5 6
5 6 7
6 7 8
7 8 9
8 9 10
9 10 11

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by