Adds one element in vector from another, by position in array
Show older comments
Say I have a vector 'x' that is [1:100], and I want to create a function that creates a new vector 'y' that is the sum of x(n+2)+x(n+3) at each position (n) of x (beginning at 1 and moving through the vector). What would this function look like?
This is my attempt at the function, but it does not work
for i=1:size(x)
y(i) = [x(i+2)+x(i+3)]
...
end
Thank you for any help!
Accepted Answer
More Answers (1)
Walter Roberson
on 23 Dec 2020
y = x((1:end-3)+2) + x((1:end-3)+3)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!