Hi ppl
I have a 100 x 100 data which is in the form of a gaussian distribution.The data has too much noise and I want to fit a 3d gaussian to the data. I have the surface fitting tool box but it says that x,y,z dimensions should be same. But my data is like x=1x100 y=1x100 and z is 100x100. Any help would be highly appreciated.
|
|
0
|
|
|
|
Reply
|
Aishwarya
|
11/17/2009 9:09:04 PM |
|
Try the following
[X,Y] = meshgrid(x,y)
X = X(:)
Y = Y(:)
Z = z(:)
"Aishwarya " <icemails@yahoo.co.in> wrote in message
news:hdv3dg$8in$1@fred.mathworks.com...
> Hi ppl
> I have a 100 x 100 data which is in the form of a gaussian
> distribution.The data has too much noise and I want to fit a 3d gaussian
> to the data. I have the surface fitting tool box but it says that x,y,z
> dimensions should be same. But my data is like x=1x100 y=1x100 and z is
> 100x100. Any help would be highly appreciated.
|
|
0
|
|
|
|
Reply
|
Richard
|
11/17/2009 10:01:55 PM
|
|
On Nov 17, 4:09=A0pm, "Aishwarya " <icema...@yahoo.co.in> wrote:
> Hi ppl
> I have a 100 x 100 data which is in the form of a gaussian distribution.T=
he data has too much noise and I want to fit a 3d gaussian to the data. I h=
ave the surface fitting tool box but it says that x,y,z dimensions should b=
e same. But my data is like x=3D1x100 y=3D1x100 and z is 100x100. Any help =
would be highly appreciated.
--------------------------------
How is this 3D data? You have two independent variables, x and y, and
a value - this makes it a 2D function. Repeat: a 2D function.
What is your z variable? Some kind of image? It's a 2D array of
100x100 but what is it?
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
11/17/2009 11:40:23 PM
|
|
Ya.It is a 2d function as in z is a function of x and y.
I did not get that question reg z
|
|
0
|
|
|
|
Reply
|
Aishwarya
|
11/18/2009 6:48:04 AM
|
|
On Nov 18, 1:48=A0am, "Aishwarya " <icema...@yahoo.co.in> wrote:
> Ya.It is a 2d function as in z is a function of x and y.
>
> I did not get that question reg z
--------------------------------------------------
Maybe there's a built in function but you can do it the regular,
normal manual way where
xMean =3D sum(x *z) / sum(z)
yMean =3D sum(y * z) / sum(z)
and the standard deviations are the usual formulas
xStd =3D sqrt( mean(x^2 - xMean))
etc.
Of course you have to scan every pixel in the array to calculate these
values.
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
11/18/2009 11:23:35 AM
|
|
Hi,
I tried the following code in MATLAB 2009b :
clc;
clear all;
[X,Y] = meshgrid(1:100,1:100);
% x=1:1:100;
% y=1:1:100;
x=X(:);
y=Y(:);
xdata = {x,y};
fid = fopen('S3D6.bin','r+');
A = fread(fid,'double');
size(A);
%figure,imagesc(A)
fid = fopen('D6S3.bin','r+');
B = fread(fid,'double');
size(B);
%figure,imagesc(B)
C=A.*B;
size(C);
D= reshape(C,100,100,100);
D1=D(:,:,10);
D2=D1(:);
fun = @(c,xdata) c(1)*exp(-((c(2)*(xdata{1}-30)^2)+(2*c(3)*(xdata{1}-30)*(xdata{2}-40))+(c(4)*(xdata{2}-40)^2)));
c_start=[30 50 30 50];
options=optimset('TolFun',1e-12,'TolX',1e-12,'MaxFunEvals',40000,'MaxIter',50000);
t = lsqcurvefit(fun,c_start,xdata,D1,options);
% [INLP,ILP] = fminspleas(funlist,NLPstart,xdata,D1)
mesh(D1);
op= t(1)*exp(-((t(2)*(xdata{1}-30)^2)+(2*t(3)*(xdata{1}-30)*(xdata{2}-40))+(t(4)*(xdata{2}-40)^2)));
figure,mesh(op);
and im getting the error as: lsqcurvefit accepts input of type double when i include options.
When I dont include options it takes the initial params as the fitting params since the tolerance is 1e-6 and my data is e-20 range.
Any idea???
|
|
0
|
|
|
|
Reply
|
Aishwarya
|
11/19/2009 6:34:07 AM
|
|
"Aishwarya " <icemails@yahoo.co.in> wrote in message
news:he2osv$a73$1@fred.mathworks.com...
> Hi,
> I tried the following code in MATLAB 2009b :
*snip*
> t = lsqcurvefit(fun,c_start,xdata,D1,options);
*snip*
> and im getting the error as: lsqcurvefit accepts input of type double when
> i include options.
> When I dont include options it takes the initial params as the fitting
> params since the tolerance is 1e-6 and my data is e-20 range.
>
> Any idea???
Yes -- you're calling LSQCURVEFIT incorrectly. If you don't want to specify
some of the inputs, you can't just leave them out. Use empty matrices for
the bound inputs instead of omitting them. Reread HELP LSQCURVEFIT for a
description of the correct calling syntax.
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|
|
0
|
|
|
|
Reply
|
Steven
|
11/19/2009 2:53:28 PM
|
|
|
6 Replies
353 Views
(page loaded in 0.029 seconds)
|