필터 지우기
필터 지우기

How to construct this matrix without loop?

조회 수: 1 (최근 30일)
Ming
Ming 2013년 10월 28일
편집: Matt J 2013년 10월 28일
Hi, everyone:
suppose I have a vector x=[a b c d e f g h ... z]. Is it possible to construct a matrix such that:
X=[a b c d; b c d e; c d e f; d e f g; e f g h; ... w x y z];
without for-loop?
many thanks

채택된 답변

Matt J
Matt J 2013년 10월 28일
편집: Matt J 2013년 10월 28일
X = x(bsxfun(@plus,(0:22).',(1:4)))

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 28일
편집: Azzi Abdelmalek 2013년 10월 28일
Example
x=[2 4 8 12 13 19 20 25]
out=cell2mat(arrayfun(@(ii) x(ii:ii+3),(1:numel(x)-3)','un',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