Howe can I subtract neighboring numbers?

Hello,
I got a matrix like this:
>> z=[1,2,3,4]
z =
1 2 3 4
How can I substract the neighboring numbers?
Like 2-1; 3-2; 4-3; etc.
And how can I divide every number by 60 ?
Like 1/60 2/60 etc

 Accepted Answer

diff(z)
z/60

5 Comments

And how can I subtract the first number with 0?
>> z=[1,2,3,4]
z =
1 2 3 4
Like
1-0
2-1
3-2
4-3
?
How can I change the collums and the lines?
SO the result is still from "left to right "instead of "up to down"?
diff([0,z(:)'])
or
diff([0;z])
Thanks works fine!

Sign in to comment.

More Answers (0)

Products

Release

R2019a

Community Treasure Hunt

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

Start Hunting!