mean value of array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
amjad almaarafawi
am 15 Dez. 2019
Kommentiert: Image Analyst
am 16 Dez. 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.
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 15 Dez. 2019
Bearbeitet: John D'Errico
am 15 Dez. 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 Kommentare
John D'Errico
am 15 Dez. 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.
Weitere Antworten (1)
Image Analyst
am 15 Dez. 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 Kommentare
Image Analyst
am 16 Dez. 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);
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!