Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Saving an anonymous function handle to a mat-file
Date: Fri, 12 Sep 2008 17:39:02 +0000 (UTC)
Organization: Xoran Technologies
Lines: 17
Message-ID: <gae9fm$r7n$1@fred.mathworks.com>
References: <6iv5vcFn3i0U1@mid.individual.net> <gae6t8$7de$1@fred.mathworks.com> <6ivm4rFp3vmU1@mid.individual.net>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1221241142 27895 172.30.248.37 (12 Sep 2008 17:39:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 12 Sep 2008 17:39:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:490030




> 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".

That's right it won't, but you never discussed the role of y in your original post, so I could only assume that it is a parameter that would be made available when the function was loaded back in.

One approach would be to do

strrep(fstr,y,numstr(y));

before saving. 

You could also consider setting up f() as an inline function instead of an anonymous one, in a similar way.