Create a new vector by adding and subtracting each element of original vector.

3 次查看(过去 30 天)
Hello community,
I want to create a new vector by adding and subtracting each element of orginal vector. How can I do?
Example: A = [3 8 99 61]
What I want is: Output B = [2 3 4 7 8 9 98 99 100 60 61 62]

采纳的回答

madhan ravi
madhan ravi 2019-8-6
B = reshape(A + [-1;0;+1],1,[]) % or
B = reshape(bsxfun(@plus,A,[-1;0;+1]),1,[]) % if < = 2016a
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by