Thread Subject: reshape/squeeze for structs?

Subject: reshape/squeeze for structs?

From: David Doria

Date: 30 Sep, 2007 17:15:26

Message: 1 of 3

I simply want to count the number of 1's in a specific field
of a struct, like this

a(1).yesno=1;
a(2).yesno=1;
a(3).yesno=0;

if i lookat

a.yesno

i see there are two 1's and one 0.

how can i put these into a vector so i dont have to count in
a loop? Reshape and Squeeze are giving me grief because
this is a struct.

Thanks,

David

Subject: reshape/squeeze for structs?

From: Tony Fisher

Date: 30 Sep, 2007 17:54:18

Message: 2 of 3

How about?

ceri=[a.yesno] ?

"David Doria" <daviddoria@gmail.com> wrote in message
<fdolje$oiq$1@fred.mathworks.com>...
> I simply want to count the number of 1's in a specific
field
> of a struct, like this
>
> a(1).yesno=1;
> a(2).yesno=1;
> a(3).yesno=0;
>
> if i lookat
>
> a.yesno
>
> i see there are two 1's and one 0.
>
> how can i put these into a vector so i dont have to count
in
> a loop? Reshape and Squeeze are giving me grief because
> this is a struct.
>
> Thanks,
>
> David

Subject: reshape/squeeze for structs?

From: David Doria

Date: 1 Oct, 2007 12:41:12

Message: 3 of 3

wow... it's always so easy!

"Tony Fisher" <tonyfisher100@btinternet.com> wrote in
message <fdonsa$ld9$1@fred.mathworks.com>...
> How about?
>
> ceri=[a.yesno] ?
>
> "David Doria" <daviddoria@gmail.com> wrote in message
> <fdolje$oiq$1@fred.mathworks.com>...
> > I simply want to count the number of 1's in a specific
> field
> > of a struct, like this
> >
> > a(1).yesno=1;
> > a(2).yesno=1;
> > a(3).yesno=0;
> >
> > if i lookat
> >
> > a.yesno
> >
> > i see there are two 1's and one 0.
> >
> > how can i put these into a vector so i dont have to count
> in
> > a loop? Reshape and Squeeze are giving me grief because
> > this is a struct.
> >
> > Thanks,
> >
> > David
>

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
 

MATLAB Central Terms of Use

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 Terms prior to use.

Contact us at files@mathworks.com