Filter löschen
Filter löschen

Finding change in direction

4 Ansichten (letzte 30 Tage)
Tala Dannawi
Tala Dannawi am 22 Apr. 2022
Bearbeitet: Tala Dannawi am 28 Apr. 2022
I would like to check all neighbor elements for every element in a 600x400 matrix for a change in direction
for i=1:size(gx,1)
for j=1:size(gx,2)
el_1=matrix(i,j) % Give the value of present element having position i,j
el_2=matrix(i,j-1) % Left element
el_3=matrix(i,j+1) % Right element
el_4=matrix(i-1,j) % for upper element
el_5=matrix(i+1,j)%Upper element
el_6=matrix(i-1,j-1) % West-North Diagonal Element....
if el_1*el_2<0
.....
end
end
I thought of checking each element

Antworten (1)

Bruno Luong
Bruno Luong am 22 Apr. 2022
Your code will crash since indexing will be overflowed.
Just an idea you might do the sign comparison of the entire array
[r,c] = find(matrix(:,1:end-1) .* matrix(:,2:end) < 0);
...
The use r, c to do whatever you want to do next.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by