How to obtain the absolute difference between elements in column?

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?

Antworten (1)

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()

Kategorien

Mehr zu Images finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 19 Mär. 2018

Beantwortet:

am 19 Mär. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by