Top Average
이전 댓글 표시
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
Jan
2011년 11월 22일
The usual procedure for homework questions is, that you show, what you have done so far and ask a specific question. If we post solutions, you could hardly claim, that you've solved your homework by your own.
@Walter: It might be useful to know, what you have changed.
Walter Roberson
2011년 11월 22일
I code-indented the first part, as it was obviously a quote from an assignment.
Jan
2011년 11월 22일
Thanks, Walter. I hope you get extra-credits for the night-shift.
채택된 답변
추가 답변 (2개)
Andrei Bobrov
2011년 11월 22일
0 개 추천
[deleted]
댓글 수: 4
Jan
2011년 11월 22일
@Andrei: It is not really helpful to solve homework questions. What will Stephanie's teacher think about this solution?
Andrei Bobrov
2011년 11월 22일
Hi Jan! A teacher may request an explanation of this solution
Jan
2011년 11월 22일
@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
2011년 11월 22일
Stephanie would be shipped to the MATLAB help.
e.g. http://www.mathworks.com/help/techdoc/ :)
Image Analyst
2011년 11월 22일
Hint:
thresholdedIndexes = yourArray > thresholdValue;
Then look up "logical indexing" and inputdlg() in the help.
댓글 수: 3
Jan
2011년 11월 22일
"inputdlg()"? No doubt, it is not a bad idea to read the documentation of "inputdlg", but it does not concern the question. So I'd suggest to read "doc save" instead, or even better: http://matlab.wikia.com/wiki/FAQ - profit from the problems of others!
Image Analyst
2011년 11월 22일
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
2011년 11월 22일
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.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!