How to use Matlab to fill gaps

조회 수: 6 (최근 30일)
M.S. Khan
M.S. Khan 2019년 7월 27일
댓글: M.S. Khan 2019년 7월 30일
If I have matrix in this shape. M =[0 0 0; 2 2 3; 3 3 0; 0 0 0; 3 3 0; 2 2 3; 0 0 0; 3 3 2; 0 0 0; 3 3 3] How can I fill: 3 0 0 3 —> 3 3 3 3 3 0 3 0 2 —> 3 3 3 0 2 3 0 3 2 0 3 0 3 —> 3 3 3 2 0 3 3 3 Regards in advance for sharing knowledge
  댓글 수: 4
M.S. Khan
M.S. Khan 2019년 7월 27일
I am using interpol1() ruction but it is not filling gaps
darova
darova 2019년 7월 27일
What is 'gap'?

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

채택된 답변

Matt J
Matt J 2019년 7월 27일
This might be what you are looking for
Mnew=M;
[nr,nc]=size(M);
xq=(1:nr).';
for i=1:nc
m=M(:,i);
[x,~,y]=find(m);
vals=interp1(x,y,xq);
m((m==0)&(vals==3))=3;
Mnew(:,i)=m;
end
M, Mnew
M =
0 0 0
2 2 3
3 3 0
0 0 0
3 3 0
2 2 3
0 0 0
3 3 2
0 0 0
3 3 3
Mnew =
0 0 0
2 2 3
3 3 3
3 3 3
3 3 3
2 2 3
0 0 0
3 3 2
3 3 0
3 3 3
  댓글 수: 1
M.S. Khan
M.S. Khan 2019년 7월 30일
Thanks Dear Matt. Warm regards

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labyrinth problems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by