Re: applying an average to individual fields within a struct array
- From: "Jos " <DELjos@xxxxxxxxxxx>
- Date: Tue, 21 Oct 2008 07:29:02 +0000 (UTC)
"Kent Williams" <k3nt00@xxxxxxxxx> wrote in message <gdjut1$jue$1@xxxxxxxxxxxxxxxxxx>...
....
....fn = fieldnames(mainStruct) ;
Data = mainStruct(1).(fn{1})
Well that enables me to sum a specific field. What is the advantage of the fieldnames? Couldn't you just access the same way doing "mainStruct(1).FieldName" ?
Yes you can, but you specifically asked for the first field ...
Anyways now how would I go about counting how many numbers are in the field? Am I going about the correct way of taking the average for a specific field?
I use
Sum = sum(mainStruct(1).FieldName)
then divide by the count of numbers in the field
In your example, the construct mainStruct(1).Fieldname refers to a list of numbers (aka a double array) which you can simply pass to other functions accepting such a list, such as SIZE, NUMEL, LENGTH.
Is there a better way to perform this calculation?
yes, take a look at MEAN
hth
Jos
.
- References:
- applying an average to individual fields within a struct array
- From: Kent Williams
- Re: applying an average to individual fields within a struct array
- From: Jos
- Re: applying an average to individual fields within a struct array
- From: Kent Williams
- applying an average to individual fields within a struct array
- Prev by Date: Re: to pick a specific value from input data
- Next by Date: One string from cell array of strings?
- Previous by thread: Re: applying an average to individual fields within a struct array
- Next by thread: Re: applying an average to individual fields within a struct array
- Index(es):
Relevant Pages
|