[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

handles to nested functions

From: Tim Josef
Subject: handles to nested functions
Date: Thu, 18 Dec 2014 14:40:25 +0100


I have the following function "fun()" which uses fminunc to find a solution for an optimization problem. I want to use the function "fx()" to store the history of the values of the objective function after each iteration. (for simplicity the example just increments the value of the variable res) The code produces the error:

error: handles to nested functions are not yet supported
error: evaluating argument list element number 4
error: called from:
error:   /tmp/fun.m at line 9, column 17

Here is the code:

function res = fun()
        X = rand(5, 5);
        y = rand(5, 1);
        t = rand(5, 1);

        res = 12;

        options = optimset("MaxIter", 100, "OutputFcn", @fx);
        fminunc(@(t)(fm(X, y, t)), t, options)

        function stop = fx(t, optimvalues, state)
                res = res + 1
                stop = false;

function [J] = fm(X, y, theta)
        c = X * theta - y;
        J = c' * c / (2 * length(y));

Is there a workaround for this?

Thanks in advance.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]