mean value of array

조회 수: 1 (최근 30일)
amjad almaarafawi
amjad almaarafawi 2019년 12월 15일
댓글: Image Analyst 2019년 12월 16일
I would appreciated if someone can tell me what am I doing wrong or maybe ?
all the matrix are 20x1 in my varibles
[Relative_ErrorM, indexAtM] = mean(Relative_Error,'omitnan');
r_experM= r_exper(indexAtM,);
plot(r_experM,Relative_ErrorM, 'kv', 'LineWidth', 2, 'MarkerSize', 15);
text(r_experM,Relative_ErrorM,sprintf(' Mean = %.1f', Relative_ErrorM))
here is the error message
Error using mean
Too many output arguments.

채택된 답변

John D'Errico
John D'Errico 2019년 12월 15일
편집: John D'Errico 2019년 12월 15일
Why do you use mean with TWO output arguments?
[Relative_ErrorM, indexAtM] = mean(Relative_Error,'omitnan');
Note that the documentation for mean does not show such a usage. You cannot make up behavior for a function, and hope that MATLAB will know what you wanted to see.
In fact, the error message, telling you that there were too many output arguments, and then showing the line in quetion should have suggested exactly this.
  댓글 수: 2
amjad almaarafawi
amjad almaarafawi 2019년 12월 15일
thank you for your response , but Im trying to graph it with a marker. I don't know how else i can get the x value for that mean value.
John D'Errico
John D'Errico 2019년 12월 15일
There will be no x value in general for a mean value. Why do you think there should be that?
For example, suppose you have the vector:
V = [1 6 2];
The mean value for that vector is 3. What is the x value you would want to see? No element in the vector takes on the value 3.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2019년 12월 15일
Note that the mean of an array won't necessarily fall at ANY index. It's quite possible the mean is not one of hte numbers in the array. For example mean([1,2]) is 1.5 but 1.5 is not in the array. Did you perhaps mean min() or max() instead of mean()? Those functions can return the index where the first occurrence of the min or max appears.
  댓글 수: 2
amjad almaarafawi
amjad almaarafawi 2019년 12월 15일
well done .. the question now is there any way I can marker the mean point with value displayesd on the graph ?
Image Analyst
Image Analyst 2019년 12월 16일
No, since you don't have an "x" value. However, you can put a marker on the actual value that is closest to the mean.
plot(x, y, 'b-', 'LineWidth', 2); % Plot curve.
% Find mean y value.
meanYValue = mean(y);
% Find out differences between actual y values and the mean y value.
diffs = abs(y - meanYValue);
% Find the index the y value is closest to the mean y value.
[minDiff, indexAtMinDiff] = min(diffs);
% Plot a circle around that point.
hold on
plot(x(indexAtMinDiff), y(indexAtMinDiff), 'ro', 'MarkerSize', 20);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by