Storing the positions of neighbouring elements that have specific values.
2 次查看(过去 30 天)
显示 更早的评论
A = zeros(5,5);
A(3,4)=1;
A(4,1)=1
I have a matrix of zeros with two 1's in postions (3,4) and (4,1). Starting with the 1 at (3,4) I want to store all the positions of neighbouring elements that are eqaul to 0. I want to do this as my next step is to choose one of the neighbours that equal 0, change that to a 1, and then start the whole process again, starting at any element that equals 1.
0 个评论
采纳的回答
dpb
2019-11-27
>> i0=3; j0=4;
>> [i,j]=find(~A(i0-1:i0+1,j0-1:j0+1));
>> [i,j]
ans =
1.00 1.00
2.00 1.00
3.00 1.00
1.00 2.00
3.00 2.00
1.00 3.00
2.00 3.00
3.00 3.00
>>
You'll have to restrict search to either include only interior initial points or modify to account for location on boundary in computing range vectors.
更多回答(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!