substract an element from previous element in a matrix
Show older comments
i have a k vector that contains 5 elements.
i want to write a code that substract - the second element from first
- the third element from second
- the fourth element from third
- the fifth element from fourth
and put them all in a vector form that will contain 4 elements
b=[k(2)-k(1) k(3)-k(2) k(4)-k(3) k(5)-k(4)];
how can i do that?
Answers (1)
Star Strider
on 10 May 2022
0 votes
3 Comments
Mahmoud Chawki
on 10 May 2022
Torsten
on 10 May 2022
b = diff(k.^2)
Star Strider
on 10 May 2022
@Torsten — Thank you!
Categories
Find more on Multidimensional Arrays 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!