Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Dynamic Fields

Subject: Dynamic Fields

From: Ashwath Sundaresan

Date: 04 Mar, 2008 03:18:02

Message: 1 of 3

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'

Cheers

Subject: Re: Dynamic Fields

From: Steven Lord

Date: 04 Mar, 2008 04:17:41

Message: 2 of 3


"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


Subject: Re: Dynamic Fields

From: per isakson

Date: 04 Mar, 2008 04:18:02

Message: 3 of 3

"Ashwath Sundaresan" <asu33@student.canterbury.ac.nz> wrote
in message <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'
>
> Cheers
>

J is that a character string or a cell array (1x1) of
strings? Should be the former / per

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics