Create a new vector by adding and subtracting each element of original vector.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alex
am 6 Aug. 2019
Bearbeitet: Adam Danz
am 6 Aug. 2019
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]
0 Kommentare
Akzeptierte Antwort
madhan ravi
am 6 Aug. 2019
B = reshape(A + [-1;0;+1],1,[]) % or
B = reshape(bsxfun(@plus,A,[-1;0;+1]),1,[]) % if < = 2016a
3 Kommentare
madhan ravi
am 6 Aug. 2019
Thanks Adam :), at first sight the question seemed to be unclear actually.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!