Path: news.mathworks.com!newsfeed-00.mathworks.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: Christian Zietz <newsgroup@chzsoft.com.ar>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Saving an anonymous function handle to a mat-file
Date: Fri, 12 Sep 2008 19:10:44 +0200
Lines: 25
Message-ID: <6ivm4rFp3vmU1@mid.individual.net>
References: <6iv5vcFn3i0U1@mid.individual.net> <gae6t8$7de$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net rdFIFM1A9oHWmyZEUrr0Gwk4dlqj5q0MdgB84lEVPkrkTLHg==
Cancel-Lock: sha1:1+en8hZM7evA1R8dnT4wEC/mtJY=
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.8.1.15) Gecko/20080621 SeaMonkey/1.1.10 Mnenhy/0.7.5.0
In-Reply-To: <gae6t8$7de$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:490025



Matt schrieb:

> You could do func2str(f) and save the function as a string. Then
> reconvert it using eval when loading it back in from the .mat file

> y = 1;
> f = @(x)(x+y);
> fstr=func2str(f)
> save foobar fstr;

> Then later

> load foobar fstr;
> f=eval(fstr);

This won't work unless I also save all variables involved in the 
anonymous function (in this case it's only "y"), because "y" will be 
undefined (or even worse: have another value) when I reload foobar.mat 
and evaluate "fstr".

Christian
-- 
Christian Zietz  -  CHZ-Soft  -  czietz (at) gmx.net
WWW: http://www.chzsoft.com.ar/
PGP/GnuPG-Key-ID: 0x6DA025CA