注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Mr.Right

不顾一切的去想,于是我们有了梦想。脚踏实地的去做,于是梦想成了现实。

 
 
 

日志

 
 
关于我

人生一年又一年,只要每年都有所积累,有所成长,都有那么一次自己认为满意的花开时刻就好。即使一时不顺,也要敞开胸怀。生命的荣枯并不是简单的重复,一时的得失不是成败的尺度。花开不是荣耀,而是一个美丽的结束,花谢也不是耻辱,而是一个低调的开始。

网易考拉推荐

二维高斯曲面拟合matlab  

2013-03-14 23:34:39|  分类: 编程 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
I'm pretty new to Matlab myslef, and I have never had any formal instruction, so I'll explain how I have fit 2D gaussians to my own data and hopefully it will help you figure out how to use it for your application.

-First you need to put your data into x, y and z variables.  For instance, my z data is in a 13x19 matrix that looks like this: 
z=[0 0 0 0 0 1 0 1 0 1 0 0 0
0 0 0 1 1 0 0 0 0 1 1 0 0
0 0 1 0 0 2 1 1 0 0 1 0 1
0 0 0 0 0 0 1 1 1 0 1 1 0
0 0 0 0 0 1 2 2 3 5 0 0 0
0 1 2 4 1 5 13 4 3 9 0 2 0
1 1 8 10 10 14 22 23 9 10 0 0 0
5 4 6 15 21 21 24 24 17 16 0 1 0
4 9 12 24 20 28 34 30 13 19 0 1 0
2 5 13 17 31 31 35 39 20 18 0 0 0
2 6 13 22 28 34 46 35 13 20 0 1 1
5 7 12 14 31 27 39 27 14 12 0 1 0
6 6 10 17 18 32 28 27 17 6 1 0 1
3 4 7 10 15 18 17 11 11 11 2 0 1
1 1 7 8 12 14 8 9 4 2 1 0 1
1 1 1 3 3 6 5 5 3 0 0 0 1
1 1 0 3 1 0 1 1 0 1 0 3 0
1 1 0 0 0 1 0 0 1 2 0 0 1
0 1 1 0 0 0 0 1 1 0 0 0 2];

-to make this 13x19 matrix into x, y, z variables that can be used with the surface fitting tool, do this:
[x,y]=meshgrid(1:13,1:19);
x=x(:);
y=y(:);
z=z(:);

-now call the surface fitting tool:
cftool

-choose x, y and z for the inputs

-choose custom equation from the drop down menu and paste in this equation:
a1*exp(-(x-x0)^2/(2*sigmax^2)-(y-y0)^2/(2*sigmay^2))

-click 'Fit'

-if the equation doesn't fit at all, change the fit options:
change all of the StartPoints to 10

--after doing this you should get these results:
General model:
       f(x,y) = a1*exp(-(x-x0)^2/(2*sigmax^2)-(y-y0)^2/(2*sigmay^2))
Coefficients (with 95% confidence bounds):
       a1 =       39.23  (37.56, 40.9)
       sigmax =       2.332  (2.232, 2.431)
       sigmay =       2.725  (2.61, 2.841)
       x0 =       6.585  (6.486, 6.684)
       y0 =       10.64  (10.52, 10.75)

Goodness of fit:
  SSE: 1723
  R-square: 0.924
  Adjusted R-square: 0.9227
  RMSE: 2.668


--To make this much faster you can choose File/Generate M-File and it will make a function called createSurfaceFit, that can be run with any data that is named x, y and z and is in the proper format.  That way you won't have to enter the cftool each time.

Hope this helps!

  评论这张
 
阅读(2266)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016