Matlab:基于参数动态创建函数

时间:2014-06-09 19:22:41

标签: matlab function anonymous-function

我有一个像这样的匿名函数:

  F = @(xy) (2*r(ti,1) .* hypot(xy(1)-BS(1,1), xy(2)-BS(1,2)) + (hypot(xy(1)-BS(1,1), xy(2)-BS(1,2))).^2 ...
                  +2*r(ti,2) .* hypot(xy(1)-BS(2,1), xy(2)-BS(2,2)) + (hypot(xy(1)-BS(2,1), xy(2)-BS(2,2))).^2 ...
                  +2*r(ti,3) .* hypot(xy(1)-BS(3,1), xy(2)-BS(3,2)) + (hypot(xy(1)-BS(3,1), xy(2)-BS(3,2))).^2 ...
                  +2*r(ti,4) .* hypot(xy(1)-BS(4,1), xy(2)-BS(4,2)) + (hypot(xy(1)-BS(4,1), xy(2)-BS(4,2))).^2 );

我需要将其转换为动态如下所示,以便该函数将根据我提供的参数具有重复部分:

 for m=1:n
     F = @(xy) (2*r(ti,1) .* hypot(xy(1)-BS(m,1), xy(2)-BS(m,2)) + (hypot(xy(1)-BS(m,1), xy(2)-BS(m,2))).^2 +F );

使用匿名功能我不能这样做。是否有可能根据参数创建一些能为我构建函数的东西?

0 个答案:

没有答案