필터 지우기
필터 지우기

How to store results from a function?

조회 수: 3 (최근 30일)
Ara Jo
Ara Jo 2021년 3월 17일
답변: Rashed Mohammed 2021년 3월 23일
Hello,
I'm using fminsearch to find parameters (para) that minimize the objective function. To exaplain, I have the following line that calls 'myfunction' that calculates the objective function:
[parahat,fval,exitflag] = fminsearch(@(para)myfunction(para), para0, X,opts);
where 'para0' contains initial values, X are some input arguments, and 'parahat' containes the estimated parameters. Here, I'm wondering if there's a way to save some results from 'myfunction' produced in the process of getting to the objective function. myfunction is written as :
function [dist] = myfunction(para, X)
and in reaching 'dist' which is to be minimized, the function calculates some values, let's say Y and Z.
Is there a way to report Y and Z calculated based on 'parahat' (so the last Y and Z in the process of searching for the minimum) along with 'parahat' and 'fval'?
Thank you very much for your help in advance.

답변 (1개)

Rashed Mohammed
Rashed Mohammed 2021년 3월 23일
Hi Ara,
Please refer to the documentation of assignin function to create variables in a specific workspace when the code is running in a different workspace.
Hope this helps

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by