From: Pavel Psota on
Hello everybody,

I am not able to overcome following problem so I´d like to please you for help. I have calculated a matrix which contains only small amount of important data. These values are formed in an one pixel width curves (skeleton), other values are NaN as can be seen bellow.

NaN NaN NaN 0.5 NaN 0.4
NaN NaN 0.5 NaN 0.4 NaN
NaN 0.5 NaN NaN 0.4 NaN
0.5 NaN NaN NaN NaN 0.4

Now I´d like to interpolate the data to get the same sized matrix but with interpolated ('cubic') values instead of NaN.

For example first two rows:
0.65 0.6 0.55 0.5 0.45 0.4
0.6 0.55 0.5 0.45 0.4 0.35
....

I have tried to solve this problem by calculation of number of NaN between each two data point in a certain row and then using interp1 function. I did it row by row. It works right only for some kinds of input matrices and also it seems me little bit jerky.

If anybody has an idea, please, help me. I´ll be grateful for all responses!

Thanks a lot,

best regards
Pavel
From: Ross W on
"Pavel Psota" <pavel.psota(a)seznam.cz> wrote in message <i3bb4o$sdj$1(a)fred.mathworks.com>...
> Hello everybody,
>
> I am not able to overcome following problem so I´d like to please you for help. I have calculated a matrix which contains only small amount of important data. These values are formed in an one pixel width curves (skeleton), other values are NaN as can be seen bellow.
>
> NaN NaN NaN 0.5 NaN 0.4
> NaN NaN 0.5 NaN 0.4 NaN
> NaN 0.5 NaN NaN 0.4 NaN
> 0.5 NaN NaN NaN NaN 0.4
>
> Now I´d like to interpolate the data to get the same sized matrix but with interpolated ('cubic') values instead of NaN.
>
> For example first two rows:
> 0.65 0.6 0.55 0.5 0.45 0.4
> 0.6 0.55 0.5 0.45 0.4 0.35
> ...
>
> I have tried to solve this problem by calculation of number of NaN between each two data point in a certain row and then using interp1 function. I did it row by row. It works right only for some kinds of input matrices and also it seems me little bit jerky.
>
> If anybody has an idea, please, help me. I´ll be grateful for all responses!
>
> Thanks a lot,
>
> best regards
> Pavel

Hi

Did you look at interp2 ?

Ross
From: John D'Errico on
"Pavel Psota" <pavel.psota(a)seznam.cz> wrote in message <i3bb4o$sdj$1(a)fred.mathworks.com>...
> Hello everybody,
>
> I am not able to overcome following problem so I´d like to please you for help. I have calculated a matrix which contains only small amount of important data. These values are formed in an one pixel width curves (skeleton), other values are NaN as can be seen bellow.
>
> NaN NaN NaN 0.5 NaN 0.4
> NaN NaN 0.5 NaN 0.4 NaN
> NaN 0.5 NaN NaN 0.4 NaN
> 0.5 NaN NaN NaN NaN 0.4
>
> Now I´d like to interpolate the data to get the same sized matrix but with interpolated ('cubic') values instead of NaN.
>
> For example first two rows:
> 0.65 0.6 0.55 0.5 0.45 0.4
> 0.6 0.55 0.5 0.45 0.4 0.35
> ...
>
> I have tried to solve this problem by calculation of number of NaN between each two data point in a certain row and then using interp1 function. I did it row by row. It works right only for some kinds of input matrices and also it seems me little bit jerky.
>
> If anybody has an idea, please, help me. I´ll be grateful for all responses!

This is exactly the problem that inpaint_nans was
designed for.

http://www.mathworks.com/matlabcentral/fileexchange/4551

John
From: Pavel Psota on
"John D'Errico" <woodchips(a)rochester.rr.com> wrote in message <i3bdl8$6n6$1(a)fred.mathworks.com>...
> "Pavel Psota" <pavel.psota(a)seznam.cz> wrote in message <i3bb4o$sdj$1(a)fred.mathworks.com>...
> > Hello everybody,
> >
> > I am not able to overcome following problem so I´d like to please you for help. I have calculated a matrix which contains only small amount of important data. These values are formed in an one pixel width curves (skeleton), other values are NaN as can be seen bellow.
> >
> > NaN NaN NaN 0.5 NaN 0.4
> > NaN NaN 0.5 NaN 0.4 NaN
> > NaN 0.5 NaN NaN 0.4 NaN
> > 0.5 NaN NaN NaN NaN 0.4
> >
> > Now I´d like to interpolate the data to get the same sized matrix but with interpolated ('cubic') values instead of NaN.
> >
> > For example first two rows:
> > 0.65 0.6 0.55 0.5 0.45 0.4
> > 0.6 0.55 0.5 0.45 0.4 0.35
> > ...
> >
> > I have tried to solve this problem by calculation of number of NaN between each two data point in a certain row and then using interp1 function. I did it row by row. It works right only for some kinds of input matrices and also it seems me little bit jerky.
> >
> > If anybody has an idea, please, help me. I´ll be grateful for all responses!
>
> This is exactly the problem that inpaint_nans was
> designed for.
>
> http://www.mathworks.com/matlabcentral/fileexchange/4551
>
> John


Thank you both very much. The John´s function is absolutely the thing. Good job, thanks :o). Have nice time!!!
From: Steven_Lord on


"Pavel Psota" <pavel.psota(a)seznam.cz> wrote in message
news:i3bb4o$sdj$1(a)fred.mathworks.com...
> Hello everybody,
>
> I am not able to overcome following problem so I´d like to please you for
> help. I have calculated a matrix which contains only small amount of
> important data. These values are formed in an one pixel width curves
> (skeleton), other values are NaN as can be seen bellow.
>
> NaN NaN NaN 0.5 NaN 0.4
> NaN NaN 0.5 NaN 0.4 NaN
> NaN 0.5 NaN NaN 0.4 NaN
> 0.5 NaN NaN NaN NaN 0.4
>
> Now I´d like to interpolate the data to get the same sized matrix but with
> interpolated ('cubic') values instead of NaN.
>
> For example first two rows:
> 0.65 0.6 0.55 0.5 0.45 0.4
> 0.6 0.55 0.5 0.45 0.4 0.35

Only part of that is interpolation. Filling in the upper-left corner will
require extrapolation (since it's outside the region where you have data),
and that can be dangerous if taken too far. I'm reminded of one of John
D'Errico's favorite quotes:

"In the space of one hundred and seventy-six years the Lower Mississippi has
shortened itself two hundred and forty-two miles. That is an average of a
trifle over one mile and a third per year. Therefore, any calm person, who
is not blind or idiotic, can see that in the Old Oölitic Silurian Period,
just a million years ago next November, the Lower Mississippi River was
upwards of one million three hundred thousand miles long, and stuck out over
the Gulf of Mexico like a fishing rod. And by the same token any person can
see that seven hundred and forty-two years from now the Lower Mississippi
will be only a mile and three quarters long, and Cairo and New Orleans will
have joined their streets together, and be plodding comfortably along under
a single mayor and a mutual board of aldermen. There is something
fascinating about science. One gets such wholesale returns of conjecture out
of such a trifling investment of fact."

http://en.wikiquote.org/wiki/Life_on_the_Mississippi [chapter 17]

While John's INPAINT_NANS tool may be appropriate for this task, you should
probably think very carefully to make sure it's doing the right thing for
your problem when it does that extrapolation.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com