Finding a specific arrangement of numbers in a matrix?

조회 수: 3 (최근 30일)
John
John 2018년 1월 10일
댓글: Stephen23 2018년 1월 11일
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
Stephen23
Stephen23 2018년 1월 11일
"Hello, how do i find a specific arrangement of numbers in a matrix?"
Use conv2.

댓글을 달려면 로그인하십시오.

답변 (1개)

Birdman
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;

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by