Finding a specific arrangement of numbers in a matrix?
1 次查看(过去 30 天)
显示 更早的评论
Hello, how do i find a specific arrangement of numbers in a matrix?
For example, I have this matrix
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0
How do I find the specific arrangement of
0 1 1 0
0 1
1 0
Also, I would like to change the 1's to 5
1 个评论
回答(1 个)
Birdman
2018-1-11
%finding specific arrangement of zeros and ones
Acol=diff(A);%column-wise comparison
Arow=diff(A.').';%row-wise comparison
%%finding indices of transitions
[rC0_1,cC0_1]=find(Acol==1);
[rC1_0,cC1_0]=find(Acol==-1);
[rR0_1,cR0_1]=find(Arow==1);
[rR1_0,cR1_0]=find(Arow==-1);
%replace 1 with 5's
A(A==1)=5;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!