フィルターのクリア

How to construct this matrix without loop?

3 ビュー (過去 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 Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by