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 20:19:55 +0200
Lines: 33
Message-ID: <6ivq6eFpuqbU1@mid.individual.net>
References: <6iv5vcFn3i0U1@mid.individual.net> <gae6t8$7de$1@fred.mathworks.com> <6ivm4rFp3vmU1@mid.individual.net> <gae9fm$r7n$1@fred.mathworks.com> <gaea81$8ve$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 TIPe9giWmbuKTnrWRN/V2gEztdrTqICejuWjxTD6f+hnNhDw==
Cancel-Lock: sha1:NvN9JjK4lDQbr/6PLjfWSidY6mQ=
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: <gaea81$8ve$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:490036



Matt schrieb:

> Of course, if you then try to evaluate the anonymous function f(x),
> you will get an error unless you first provide y, but presumably you
> have a way of doing that. Otherwise, why would you want to re-use the
> function on a different machine?

When you declare a function handle, MATLAB "freezes" the current 
workspace and saves it together with the function handle. You can go

y = 1;
f = @(x)(x+y)
clear y;

and

f(3)

will still evaluate to 4. Even if you now enter

y = pi;

f(3) will still be 4.

When you save a function handle to a mat-file the workspace at the time 
the function was defined is also saved. This obviously doesn't happen if 
you just save the string that is func2str(f).

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