Path: news.mathworks.com!not-for-mail
From: "Yuri Geshelin" <geshelin@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: eval, feval, global
Date: Thu, 27 Mar 2008 17:45:04 +0000 (UTC)
Organization: Bedford Institute of Oceanography
Lines: 47
Message-ID: <fsgmf0$fcd$1@fred.mathworks.com>
References: <fsebf0$43u$1@fred.mathworks.com> <fsg56d$50c$1@fred.mathworks.com>
Reply-To: "Yuri Geshelin" <geshelin@hotmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1206639904 15757 172.30.248.35 (27 Mar 2008 17:45:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 27 Mar 2008 17:45:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1149396
Xref: news.mathworks.com comp.soft-sys.matlab:459515


All right, here is the second typical situation, in which I 
use EVAL. It is not about computational cost, just a 
programming habit.


I have PLOT in the body of my function, and sometimes I 
want to do


plot(A.TEMP)


at other times it would be another text string:


plot(A.PSAL)


At the time of the call to the function I do not know, 
which field should be plotted.
So I pass the array of text strings in the function (it 
gets passed for other reasons, too):


prop = {'TEMP', 'PSAL', ...........}


And once I compute the index of the required field (irf), I 
do this:


eval(['plot(A.' prop{irf} ')'])


Clumsy, but I got very much used to it. What would be your 
recommendation?


(I wanted to stay away from CASE, because the number of 
fields is quite big).


Thanks,


Yuri