help with using function handle
显示 更早的评论
Hi,
i am using a funcion handle to fit a function which is sum of Guassian distributions to a given set of data. I have stored the details of the Guassian distributions in vector 'x'. It all works fine. I am having trouble writing the final values of gT to a file as gT is not the output to the main code. Tried to write within the function 'parameters' but did not work.
Also, this guassian distribution functions need to fit to multiple sets of data so the part of the main code is running in a for loop too.
part of my code is below.
Any suggetion to help with this is appreciated. thanks,
main code:
func =@(x)parameters(x,T2,fT2);
x_updated = fminsearch(func, x);
The function parameters is below.
function [E] = parameters(x, T2, fT2)
mu = x(1:3:end)
std = x(2:3:end)
h = x(3:3:end)
gT1 = h(1)*(exp(-(T2-mu(1)).^2/(2*std(1)^2)));
gT2 = h(2)*(exp(-(T2-mu(2)).^2/(2*std(2)^2)));
gT3 = h(3)*(exp(-(T2-mu(3)).^2/(2*std(3)^2)));
gT = gT1 +gT2 + gT3;
E = sum(gT - fT2).^2;
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logistic Distribution 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!