How to obtain the absolute difference between elements in column?
Show older comments
Hi I have
a= 4 3 2 1
4 3 1 2
4 2 3 1
I want to know the absolute difference between elements for each of the columns which gives me
b= 0 0 -1 1
0 -1 2 -1
How am I going to do this?
Answers (1)
Walter Roberson
on 19 Mar 2018
b = diff(a);
would give the sample output you show.
However, your description asks for the absolute difference, and absolute difference is never negative, so your b does not match your question. To match your question you would abs() the diff()
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!