Bizarre results with inpaint_nans

3 vues (au cours des 30 derniers jours)
Sabbas
Sabbas le 8 Août 2012
Dear all,
I have
A={
[4.1583] [4.2132] [1.4600e+004] [100]
[4.0339] [4.1117] [1.4948e+004] [100]
[3.9389] [4.0431] [1.9352e+004] [100]
[3.9676] [4.0655] [1.5374e+004] [100]
[3.9313] [4.0153] [1.5853e+004] [100]
[ NaN] [ NaN] [ NaN] [NaN]
[3.8720] [3.9659] [1.7952e+004] [100]
[3.8829] [4.0014] [1.7192e+004] [100]
[ NaN] [ NaN] [ NaN] [NaN]
[3.8681] [3.9610] [1.7790e+004] [100]
[4.3944] [3.8585] [1.7593e+004] [100]
[ NaN] [ NaN] [ NaN] [NaN]
[3.8086] [3.8981] [1.4981e+004] [100]
[3.7495] [3.8701] [1.5271e+004] [100]
[ NaN] [ NaN] [ NaN] [NaN]
[3.6838] [3.7952] [1.5973e+004] [100]
[3.7344] [3.8012] [1.6384e+004] [100]
[ NaN] [ NaN] [ NaN] [NaN]
[3.7861] [3.8795] [1.7397e+004] [100]
[3.7793] [3.8614] [1.8571e+004] [100]
[ NaN] [ NaN] [ NaN] [NaN]
[3.6177] [3.7094] [1.9622e+004] [100]
[4.2028] [3.5645] [1.9093e+004] [100]
[ NaN] [ NaN] [ NaN] [NaN]
[3.6123] [3.6857] [1.5312e+004] [100]
[3.5771] [3.6983] [1.5883e+004] [100]
[ NaN] [ NaN] [ NaN] [NaN]
[3.6439] [3.7417] [1.6312e+004] [100]
[3.6003] [3.7064] [1.6997e+004] [100]
[ NaN] [ NaN] [ NaN] [NaN]
[3.7250] [3.8390] [1.7667e+004] [100]
[3.7227] [3.8167] [1.8742e+004] [100]
[ NaN] [ NaN] [ NaN] [NaN]
[3.6667] [3.7456] [1.8926e+004] [100]
[3.9350] [3.4062] [1.8028e+004] [ 95] }
IF I apply
out=inpaint_nans(cell2mat(A) ,2);
I obtain
4.15830000000000 4.21320000000000 14600 100
4.03390000000000 4.11170000000000 14948 100
3.93890000000000 4.04310000000000 19352 100
3.96760000000000 4.06550000000000 15374 100
3.93130000000000 4.01530000000000 15853 100
3.90165000000000 2263.50209333333 9042.12552333333 100
3.87200000000000 3.96590000000000 17952 100
3.88290000000000 4.00140000000000 17192 100
3.87550000000000 2341.95677333333 9355.98919333333 100
3.86810000000000 3.96100000000000 17790 100
4.39440000000000 3.85850000000000 17593 100
4.10150000000000 2181.42882666667 8713.85720666667 100
3.80860000000000 3.89810000000000 14981 100
3.74950000000000 3.87010000000000 15271 100
3.71665000000000 2092.63518666667 8359.15879666667 100
3.68380000000000 3.79520000000000 15973 100
3.73440000000000 3.80120000000000 16384 100
3.76025000000000 2261.78425333333 9035.69606333333 100
3.78610000000000 3.87950000000000 17397 100
3.77930000000000 3.86140000000000 18571 100
3.69850000000000 2555.87181333333 10212.2179533333 100
3.61770000000000 3.70940000000000 19622 100
4.20280000000000 3.56450000000000 19093 100
3.90755000000000 2303.30873333333 9202.07718333334 100
3.61230000000000 3.68570000000000 15312 100
3.57710000000000 3.69830000000000 15883 100
3.61050000000000 2155.94680000000 8612.73670000000 100
3.64390000000000 3.74170000000000 16312 100
3.60030000000000 3.70640000000000 16997 100
3.66265000000000 2320.58881333333 9271.14720333333 100
3.72500000000000 3.83900000000000 17667 100
3.72270000000000 3.81670000000000 18742 100
3.69470000000000 2520.86853333333 10072.2171333333 100
3.66670000000000 3.74560000000000 18926 100
3.93500000000000 3.40620000000000 18028 95
If I apply
out3=[];
for c = 1:size(A,2)
out=inpaint_nans(cell2mat(A(:,c)),2);
out3=[out3 out ];
end
I obtain
4.15830000000000 4.21320000000000 14600 100
4.03390000000000 4.11170000000000 14948 100
3.93890000000000 4.04310000000000 19352 100
3.96760000000000 4.06550000000000 15374 100
3.93130000000000 4.01530000000000 15853 100
3.90165000000000 3.99060000000000 16902.5000000000 100
3.87200000000000 3.96590000000000 17952 100
3.88290000000000 4.00140000000000 17192 100
3.87550000000000 3.98120000000000 17491 100
3.86810000000000 3.96100000000000 17790 100
4.39440000000000 3.85850000000000 17593 100
4.10150000000000 3.87830000000000 16287 100
3.80860000000000 3.89810000000000 14981 100
3.74950000000000 3.87010000000000 15271 100
3.71665000000000 3.83265000000000 15622 100
3.68380000000000 3.79520000000000 15973 100
3.73440000000000 3.80120000000000 16384 100
3.76025000000000 3.84035000000000 16890.5000000000 100
3.78610000000000 3.87950000000000 17397 100
3.77930000000000 3.86140000000000 18571 100
3.69850000000000 3.78540000000000 19096.5000000000 100
3.61770000000000 3.70940000000000 19622 100
4.20280000000000 3.56450000000000 19093 100
3.90755000000000 3.62510000000000 17202.5000000000 100
3.61230000000000 3.68570000000000 15312 100
3.57710000000000 3.69830000000000 15883 100
3.61050000000000 3.72000000000000 16097.5000000000 100
3.64390000000000 3.74170000000000 16312 100
3.60030000000000 3.70640000000000 16997 100
3.66265000000000 3.77270000000000 17332 100
3.72500000000000 3.83900000000000 17667 100
3.72270000000000 3.81670000000000 18742 100
3.69470000000000 3.78115000000000 18834 100
3.66670000000000 3.74560000000000 18926 100
3.93500000000000 3.40620000000000 18028 95
AS you can see between these two outputs the 2nd and 3rd row are different. But the code was the same. Any explanation?
thanks
  1 commentaire
Oleg Komarov
Oleg Komarov le 8 Août 2012
Why don't you store your "numbers" in a double array from the beginning?
Check the different in size:
whos A
B = cell2mat(A)
whos B

Connectez-vous pour commenter.

Réponse acceptée

Oleg Komarov
Oleg Komarov le 8 Août 2012
Modifié(e) : Oleg Komarov le 8 Août 2012
inpaint_nans() uses a 4 neighborood algorithm because it's designed for images. Thus, looping by column hides the two adjacent columns.
If you don't want to loop with inpaint_nans(), then you can always use interp1():
% Convert to double (again, store them as double from the beginnig)
B = cell2mat(A);
% Values to interpolate
xi = (1:size(A,1))';
% Index the non NaN
idx = ~isnan(B(:,1));
out = interp1(xi(idx),B(idx,:),xi);
  6 commentaires
Sabbas
Sabbas le 8 Août 2012
because I do not know how to apply it when I have scattered NaNs. IN the above question if the first element of a row is NaN then the rest elements of that row are also NaN. HOw coould I modify the code
idx = ~isnan(B(:,1));
out = interp1(xi(idx),B(idx,:),xi);
when my matrix has scattered NaNs?
thanks
Oleg Komarov
Oleg Komarov le 11 Août 2012
Then you have to loop with interp1 as well.

Connectez-vous pour commenter.

Plus de réponses (1)

Sean de Wolski
Sean de Wolski le 8 Août 2012
The second and third row don't look any different to me:
4.03390000000000 4.11170000000000 14948 100
3.93890000000000 4.04310000000000 19352 100
versus
4.03390000000000 4.11170000000000 14948 100
3.93890000000000 4.04310000000000 19352 100
It's been awhile since I've used inpaint_nans but it doesn't surprise me that it would look at a 2d array differently than column vectors either.
Hopefully the master himself will chime in :)
  1 commentaire
Sabbas
Sabbas le 8 Août 2012
Modifié(e) : Sabbas le 8 Août 2012
Sorry I made a mistake.
look at the 6th and 7th row
3.90165000000000 2263.50209333333 9042.12552333333 100
3.87200000000000 3.96590000000000 17952 100
3.90165000000000 3.99060000000000 16902.5000000000 100
3.87200000000000 3.96590000000000 17952 100

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by