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

Thread Subject: simple struct question

Subject: simple struct question

From: jay vaughan

Date: 09 May, 2008 23:49:22

Message: 1 of 3

I would like to set all elements for a range of struct
fields to be the same. What I wanted to write was the
following, which MATLAB doesn't like.

A(50:100).f = 5;

I was hoping not to use a loop for this...

for k = 50:100,
    A(k).f = 5;
end


Any ideas?

Thanks,
J

Subject: Re: simple struct question

From: Doug Schwarz

Date: 10 May, 2008 00:38:07

Message: 2 of 3

In article <g02nu2$4qt$1@fred.mathworks.com>,
 "jay vaughan" <jvaughan5.nospam@gmail.com> wrote:

> I would like to set all elements for a range of struct
> fields to be the same. What I wanted to write was the
> following, which MATLAB doesn't like.
>
> A(50:100).f = 5;
>
> I was hoping not to use a loop for this...
>
> for k = 50:100,
> A(k).f = 5;
> end
>
>
> Any ideas?
>
> Thanks,
> J

[A(50:100).f] = deal(5);

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.

Subject: Re: simple struct question

From: jay vaughan

Date: 10 May, 2008 01:05:49

Message: 3 of 3

"jay vaughan" <jvaughan5.nospam@gmail.com> wrote in message
<g02nu2$4qt$1@fred.mathworks.com>...
> I would like to set all elements for a range of struct
> fields to be the same. What I wanted to write was the
> following, which MATLAB doesn't like.
>
> A(50:100).f = 5;
>
> I was hoping not to use a loop for this...
>
> for k = 50:100,
> A(k).f = 5;
> end
>
>
> Any ideas?
>
> Thanks,
> J

Thanks, Doug.
J

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
vectorize jay vaughan 09 May, 2008 19:50:21
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