matlab的fmincon中的noncol如果每次循环都是不同的函数,不想写单独的m文件,咋写呢

Duplicated, 哈哈matlab,包含多个返回值的函数如何用匿名函数的方式定义? - MATLAB
■网友
我不是很确定是否理解了你的意思。你是想定义一个函数,一些输入变量作为参数但是可以调节,别的输入变量可以用来做优化?
【matlab的fmincon中的noncol如果每次循环都是不同的函数,不想写单独的m文件,咋写呢】 这个问题可以用m文件+匿名函数来解决。举个简单的例子:
% sample_func.m:function output = sample_func(x,y) output = x+y;end% main.m:new_sample_func = @(x) sample_func(x,y);y=1;new_sample_func(1) % Should return 2y=2;new_sample_func(1) % Should return 3% Optimizationx_opt = fminsearch(new_sample_func, 0); % Of course no solution in this case不知道符不符合你的要求?


    推荐阅读