How to use Matlab to fill gaps

6 visualizaciones (últimos 30 días)
M.S. Khan
M.S. Khan el 27 de Jul. de 2019
Comentada: M.S. Khan el 30 de Jul. de 2019
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 comentarios
M.S. Khan
M.S. Khan el 27 de Jul. de 2019
I am using interpol1() ruction but it is not filling gaps
darova
darova el 27 de Jul. de 2019
What is 'gap'?

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 27 de Jul. de 2019
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 comentario
M.S. Khan
M.S. Khan el 30 de Jul. de 2019
Thanks Dear Matt. Warm regards

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Labyrinth problems en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by