finding the error between two curves from a fig

I have a fig, the onee in attaced (example).
Considering the green one the true value, how can I evaluete the error of the second?
P.S.
I have Matlab 2014b

1 件のコメント

Paul Rogers
Paul Rogers 2020 年 7 月 19 日
someone suggested this and theen deleted, but it's not working:
Open the figure and run the following commands to calculate the MSE .
% get current axes
ax = gca;
% get Y data of green and blue lines
GreenLineY = ax.Children(1).YData ;
BlueLineY = ax.Children(2).YData;
% MSE
MeanSquaredError = (GreenLineY - BlueLineY) .^2;

サインインしてコメントする。

 採用された回答

Takumi
Takumi 2020 年 7 月 19 日

0 投票

I used the findall function to find out what was plotted.
I noticed that some of the lines containing the NaN values were plotted as nonsense.
The lines you're trying to compare are probably h(2) and h(6).
In addition, the blue line contains NaN values that need to be removed.
Finally, we need to align the number of elements to compute the error, so we interpolate.
% get current axes
ax = gca;
% find object
h = findall(ax);
% get Y data of green and blue lines
GreenLineX = h(2).XData;
GreenLineY = h(2).YData;
BlueLineX = h(6).XData;
BlueLineY = h(6).YData;
% eliminate NaN
BlueLineX = rmmissing(BlueLineX);
BlueLineY = rmmissing(BlueLineY);
% interpolation
GreenLineY_interp = interp1(GreenLineX,GreenLineY,BlueLineX,'spline');
% MSE
MeanSquaredError = mean((GreenLineY_interp - BlueLineY).^2);
figure
plot(GreenLineX,GreenLineY,'-g');
hold on
plot(BlueLineX,BlueLineY,'-b');

6 件のコメント

Paul Rogers
Paul Rogers 2020 年 7 月 19 日
thatnks, man
but I got stuck here when I run the program:
GreenLineX = h(2).XData;
I don't know if it helps, but I have Matlab2014b
Takumi
Takumi 2020 年 7 月 19 日
% get current axes
ax = gca;
% find object
h = findall(ax);
% get Y data of green and blue lines
GreenLineX = h(2).XData;
GreenLineY = h(2).YData;
BlueLineX = h(6).XData;
BlueLineY = h(6).YData;
% eliminate NaN
BlueLineX= BlueLineX(~isnan(BlueLineX));
BlueLineY= BlueLineY(~isnan(BlueLineY));
% BlueLineX = rmmissing(BlueLineX);
% BlueLineY = rmmissing(BlueLineY);
% interpolation
GreenLineY_interp = interp1(GreenLineX,GreenLineY,BlueLineX,'spline');
% MSE
MeanSquaredError = mean((GreenLineY_interp - BlueLineY).^2);
figure
plot(GreenLineX,GreenLineY,'-g');
hold on
plot(BlueLineX,BlueLineY,'-b');
Paul Rogers
Paul Rogers 2020 年 7 月 19 日
I get this error message:
Index exceeds matrix dimensions.
Error in Mikko_4 (line 74)
BlueLineX = h(6).XData;
Takumi
Takumi 2020 年 7 月 19 日
Really? Your version is 2014b right?
Takumi
Takumi 2020 年 7 月 19 日
I have installed MATLAB version 2014b and it worked fine.
Paul Rogers
Paul Rogers 2020 年 7 月 19 日
sorry, It works. I just did a very stuoid mistake!
You're great, thanks for helping me.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品

リリース

R2014b

タグ

質問済み:

2020 年 7 月 19 日

コメント済み:

2020 年 7 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by