Finding change in direction
3 次查看(过去 30 天)
显示 更早的评论
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
回答(1 个)
Bruno Luong
2022-4-22
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!