Ignoring NaNs for Surface Fit

Hi,
I have a 2D matrix, with certain values missing - represented by NaNs. I have organised the data into three column vectors (x,y,z) and am able to pass the data through the Surface Fitting tool 'sftool'. This ignores the NaNs and works perfectly, however whenever I try and manually do this fit using the 'fit()' function it won't allow me because of the NaNs.
How can I ignore these NaNs in a similar way for this? All the methods I've come across for ignoring NaNs so far won't work as I have to keep all three vectors the same length and in order.
Any help would be greatly apprecitated.

 採用された回答

Sean de Wolski
Sean de Wolski 2012 年 8 月 13 日
編集済み: Sean de Wolski 2012 年 8 月 13 日

1 投票

xyz = [x y z]; %x y z are column vextors
xyz_no_nans = xyz(~any(isnan(xyz),2),:); %keep rows which have no nans
x = xyz_no_nans(:,1); %etc.

3 件のコメント

John
John 2012 年 8 月 13 日
Thanks for your reply!
Unfortunately, from what I understand, this gets rid of the entirety of any row that contains a NaN?
My matrix contains far more NaNs than actual values and so this method leaves me with empty vectors. I need a method that will not remove any of the correct values. Is there a way to do this or have a misunderstood/used your suggestion? Thanks again.
Sean de Wolski
Sean de Wolski 2012 年 8 月 13 日
How do you propose to keep a set of xyz pairs if any of them is a NaN?
x = pi,y=17,z = nan;
What useful information can you gather from the above?
John
John 2012 年 8 月 14 日
I'm sorry, I was confusing myself because this didn't work at first. I now understand what it's doing and it's exactly what I want. Have got it all working - many thanks! This has saved me hours of time...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by