mean value of array

1 vue (au cours des 30 derniers jours)
amjad almaarafawi
amjad almaarafawi le 15 Déc 2019
Commenté : Image Analyst le 16 Déc 2019
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.

Réponse acceptée

John D'Errico
John D'Errico le 15 Déc 2019
Modifié(e) : John D'Errico le 15 Déc 2019
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 commentaires
amjad almaarafawi
amjad almaarafawi le 15 Déc 2019
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 le 15 Déc 2019
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 15 Déc 2019
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 commentaires
amjad almaarafawi
amjad almaarafawi le 15 Déc 2019
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 le 16 Déc 2019
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);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by