prelocation of array entries

6 visualizaciones (últimos 30 días)
Ivan
Ivan el 23 de Abr. de 2013
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

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 23 de Abr. de 2013
Editada: Azzi Abdelmalek el 23 de Abr. de 2013
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(:)'

Más respuestas (0)

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by