Re: applying an average to individual fields within a struct array



"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
.



Relevant Pages

  • Re: Help - Need experts help!
    ... some the daily hours column with a regular SUM() function: ... HTH, ... when the cells in e & f as blank it still enters a total as it is ... taking it as 0:00 which it is counting it as 24:00 and adding this to ...
    (microsoft.public.excel.misc)
  • Re: New Twist on Old Question-Averages
    ... counting,, so you can ... Detail) contains details about course evalutions per instructor. ... Evaluation Average. ... following is the calculation as it currently works: ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Date Calculation Question for Macropod
    ... If, for example you were to use the first field under the heading 'Automatically Calculate A Past Or Future Time of Day', you could modify the Time1 and Time1 parameters code from: ... Note that the 'ss' part of the SAVEDATE always returns '00', so you can't really get a meaningful 'ss' calculation. ... Be aware, though, that this will add 1 minute to the result even where the actual SAVEDATE time occurred on an exact minute boundary. ... hour, minute, seconds and am/pm after calculation. ...
    (microsoft.public.word.docmanagement)
  • Re: How can I practice counting?
    ... calculation or technique. ... Are you prepared to take this as far as not counting on your fingers? ...
    (rec.games.bridge)
  • RE: If condition
    ... How to do this depends on the calculation you want to do. ... counting or adding you may be able to use COUNTIF or SUMIF functions to do ... > I have three columns in a separate worksheet suppose worksheet "A". ... > worksheet "A" and if a perfect match is found i want to perform calculation ...
    (microsoft.public.excel.programming)