How to construct this matrix without loop?

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

 Akzeptierte Antwort

Matt J
Matt J am 28 Okt. 2013
Bearbeitet: Matt J am 28 Okt. 2013

0 Stimmen

X = x(bsxfun(@plus,(0:22).',(1:4)))

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 28 Okt. 2013
Bearbeitet: Azzi Abdelmalek am 28 Okt. 2013

0 Stimmen

Example
x=[2 4 8 12 13 19 20 25]
out=cell2mat(arrayfun(@(ii) x(ii:ii+3),(1:numel(x)-3)','un',0))

Kategorien

Produkte

Gefragt:

am 28 Okt. 2013

Bearbeitet:

am 28 Okt. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by