How to run function over variables located within matrix?
显示 更早的评论
Hello, all. So I am a Matlab newbie, and my first major project is trying to create a function that maximizes any mathematical function that I input into it for some variables over some data observations. For ex., like finding the parameters of the normal distribution that maximizes said normal dist. function for some values of x.
Thing is, sometimes my function has more than one data source, and I'd like to be able to create one matrix, with each of its columns corresponding to a different observation the function is supposed to run over.
data1 = [1, 2, 3];
data2 = [6,7,8];
fun = @(x)(1/(2*pi*x(2)*x(4)*sqrt(1-p^2)))*exp((-1/(2-2*p^2))*((data1-x(1)).^2/(x(3)^2)+(data2-x(2)).^2/(x(4)^2)-(2*p.*(data1-x(1)).*(data2-x(2)))./(x(3)*x(4))));
fun([1,2,3,4])
Here, I get a vector of values as expected, but how could I do the same with just one "data" vector, like
data=[data1;data2];
fun([1,2,3,4]) ?
Is it possible?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!