mean value of array

2 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by