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 Center および File ExchangeLabyrinth problems についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by