prelocation of array entries
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2013년 4월 23일
편집: Azzi Abdelmalek
2013년 4월 23일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!