How to output multiple results via function
조회 수: 1 (최근 30일)
이전 댓글 표시
Maybe this is a basic question. Please help me with it. I define a function with a couple parameters.
function f=fun(y,lambda)
[y,fval]=fmincon(@(y)fun(y,lambda),y0,[],[],[],[],[],[],[],[])
y is chosen to minimize function fun. The outputs are y and fval. I would like to output some other values, for example, y*lambda. I know I can output y*lambda in the next step after fmincon. How to output y*lambda directly in the function or in optimization problem?
댓글 수: 0
채택된 답변
jgg
2016년 4월 11일
Do you mean from the function fun?
It's pretty easy:
function [f,yl,otherstuff] =fun(y,lambda)
[y,fval]=fmincon(@(y)fun(y,lambda),y0,[],[],[],[],[],[],[],[]);
yl = y*lambda;
otherstuff = otherstuff_create();
end
Like this.
댓글 수: 2
jgg
2016년 4월 11일
You have to store the output as well, or display it. For instance, you would call that function like this:
[f,yl,otherstuff] = fun(y,lambda)
I'm not sure exactly what your function is, though, so I can't be more precise.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!