Diagonal direction - difference between adjacent elements

3 Ansichten (letzte 30 Tage)
Chethan S
Chethan S am 6 Mai 2011
I have a matrix,
I = 5 4 3
9 8 6
6 3 4
How can I calculate differences between adjacent elements in a diagonal directions. I want these outputs(for first and last rows and columns I don't mind padding):
5 4 3
5 5 6
2 -3 4
and
5 4 3
9 3 2
6 -6 -4

Akzeptierte Antwort

Teja Muppirala
Teja Muppirala am 6 Mai 2011
Use 2-D convolution:
I = [ 5 4 3;
9 8 6;
6 3 4;]
I_1 = I;
I_2 = I;
I_1(2:end,1:end-1) = conv2(I,[0 1; -1 0],'valid')
I_2(2:end,2:end) = conv2(I,[1 0; 0 -1],'valid')

Weitere Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by