필터 지우기
필터 지우기

Repeat a vector with increment

조회 수: 8 (최근 30일)
John
John 2016년 12월 30일
편집: Azzi Abdelmalek 2016년 12월 30일
Given
vector a = (1:N)'; with N consecutive integers
how to generate
matrix b = [a a+1 a+2 ... a+M]; with M columns, each column incremented by one.
For example
N = 3; M = 3;
a = (1:3)';
b = [(1:3)' (2:4)' (3:5)' (4:6)'];

채택된 답변

Star Strider
Star Strider 2016년 12월 30일
This works:
N = 3;
M = 3;
a = (1:3)';
b = bsxfun(@plus, a, [0:M-1])
b =
1 2 3
2 3 4
3 4 5

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by