Let's say I have the following array: A = [2 4 6 8] and I want array B to be populated according to the following pattern: (entry from A)-1, entry from A, (entry from A)+1 so in this case B = [1 2 3 3 4 5 5 6 7 7 8 9]
How do I do this?
Thanks

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 4 月 23 日
編集済み: Azzi Abdelmalek 2013 年 4 月 23 日

0 投票

A = [2 4 6 8]
B=cell2mat(arrayfun(@(x) [x-1 x x+1],A,'un',0))
%or
B=[A-1; A ;A+1]
B=B(:)'

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by