Top Average

1 visualizzazione (ultimi 30 giorni)
Stephanie
Stephanie il 22 Nov 2011
Create a Matlab function according to the following:
Function name: topaverage
Input:
1. list of real numbers
2. real number
Output:
1. real number that is the average of all items in input #1 that are
equal to or greater than input #2
Example:
r=topaverage([3 6 10 12], 10)
r =
11
How do I get the program to relate the input #2 to one of the elements in the list and only start the average calculation from there? I know I have to sort from lowest to largest... I'm just stuck.
  3 Commenti
Walter Roberson
Walter Roberson il 22 Nov 2011
I code-indented the first part, as it was obviously a quote from an assignment.
Jan
Jan il 22 Nov 2011
Thanks, Walter. I hope you get extra-credits for the night-shift.

Accedi per commentare.

Risposta accettata

Stephanie
Stephanie il 22 Nov 2011
I actually figured it out last night.
Thank you

Più risposte (2)

Andrei Bobrov
Andrei Bobrov il 22 Nov 2011
[deleted]
  4 Commenti
Jan
Jan il 22 Nov 2011
@Andrei: Yes. And if Stephanie asks in another Matlab forum "what does '@(x,y)mean(x(x>=y))' exactly mean" I'd be naive enough to answer this.
Andrei Bobrov
Andrei Bobrov il 22 Nov 2011
Stephanie would be shipped to the MATLAB help.
e.g. http://www.mathworks.com/help/techdoc/ :)

Accedi per commentare.


Image Analyst
Image Analyst il 22 Nov 2011
Hint:
thresholdedIndexes = yourArray > thresholdValue;
Then look up "logical indexing" and inputdlg() in the help.
  3 Commenti
Image Analyst
Image Analyst il 22 Nov 2011
I thought she could use it to ask the user for one or both of the input arguments to be passed to her "topaverage" function. Seems quite reasonable to me, actually even more flexible than if they were hard coded into the m-file. On the other hand I'm not sure where she'd use save() unless it would be to save the output argument "r" to a mat file for some reason.
Jan
Jan il 22 Nov 2011
Dear Image Analyst: No, she does not need SAVE currently. But questions concerning "save(Name)" versus "save('Name')" occur such frequently in the Matlab forums, that reading "help save" four times is simply a good idea.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by