mean value of array
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
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
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
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
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!