How to smooth out or fit a surface?
Show older comments
I have my data stored in a 44 by 44 matrix. When I plot this data, it has a lot of irregular peaks. I want a smooth surface instead. (I cannot use the cftool since I've got a long loop and cannot do it manually everytime.) Following is the code I'm using but I get an error saying that x and y should be a column matrix. If I remove the fit command line, the whole code runs perfectly fine. Can someone please point out my mistake or suggest changes to this code?
x = 1:44;
y = 1:44;
for i = 1:35
a = xlsread('\\uoa.auckland.ac.nz\engdfs\Homeair.xlsx',strcat('CO',int2str(46*i-18),':','EF',int2str(46*i+25)));
b = fit([x,y,],a,'lowess');
figure;
surf(x,y,b);
axis([0 44 0 44 -50 120]);
fname = sprintf('A%d.png',i);
saveas(gcf,fname);
end
Accepted Answer
More Answers (1)
Image Analyst
on 20 May 2016
1 vote
You can do a regression to fit a 2D polynomial surface to it. See John D'Errico's polyfitn: http://www.mathworks.com/matlabcentral/fileexchange/34765-polyfitn My demo of it is attached where I get a smooth background.
1 Comment
Jasnoor Singh
on 20 May 2016
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!