Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Dynamic Fields
Date: Mon, 3 Mar 2008 23:17:41 -0500
Organization: The MathWorks, Inc.
Lines: 44
Message-ID: <fqiih5$ke6$1@fred.mathworks.com>
References: <fqif1a$dbo$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1204604261 20934 144.212.105.187 (4 Mar 2008 04:17:41 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 4 Mar 2008 04:17:41 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
Xref: news.mathworks.com comp.soft-sys.matlab:455161



"Ashwath Sundaresan" <asu33@student.canterbury.ac.nz> wrote in message 
news:fqif1a$dbo$1@fred.mathworks.com...
> Hi
>
> I currently have a 1x1 sturcture. The structure contains
> 6001x3 array.
>
> s=load('Patient1_PV_PEEP1.mat'
> J = fieldnames(s)
> n1=500;
> n2=35/0.01;
> t=s.(J)(n1:n2,1)
> P=s.v(n1:n2,2)
> V=s.v(n1:n2,3)
>
> The code loads up the mat file. This may change depending
> on the patient. Three variables in the array are time,
> pressure and volume. The name of the field is
> Patient1_PV_PEEP1 and this is variable depending on
> patient. When I attempt to use dynamic field names, the
> lines with t, P and V give me this message:
>
> 'Argument to dynamic structure reference must evaluate to a
> valid field name'

From the reference page:

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fieldnames.html

"names = fieldnames(s) returns a cell array of strings containing the 
structure field names associated with the structure s."

A cell array of strings is not a valid field name.  A valid field name is a 
string (technically, a 1-by-N char array) that satisfies the criteria listed 
in the M-file help for the ISVARNAME function.

Try "t = s.(J{1})(n1:n2, 1)"

-- 
Steve Lord
slord@mathworks.com