Borrar filtros
Borrar filtros

Finding change in direction

4 visualizaciones (últimos 30 días)
Tala Dannawi
Tala Dannawi el 22 de Abr. de 2022
Editada: Tala Dannawi el 28 de Abr. de 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

Respuestas (1)

Bruno Luong
Bruno Luong el 22 de Abr. de 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.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by