MATLAB: Finding the error between two curves from a fig errorfigureMATLAB 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 Best Answer 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 objecth = 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 NaNBlueLineX = rmmissing(BlueLineX);BlueLineY = rmmissing(BlueLineY);% interpolationGreenLineY_interp = interp1(GreenLineX,GreenLineY,BlueLineX,'spline'); % MSEMeanSquaredError = mean((GreenLineY_interp - BlueLineY).^2);figureplot(GreenLineX,GreenLineY,'-g');hold onplot(BlueLineX,BlueLineY,'-b'); Related SolutionsMATLAB: Visual stacking order of objects and plotyy In order for a line drawn on one axes to appear behind a line drawn on another axes, the entire axes of the line must be behind the other axes.You might end up having to use a third axes with the same position and axes limits as the first axes, but uistack()'d behind both other axes. MATLAB: How to create a legend with multiple colored squares % Create an axehAxe = axes(...);% Get your patches handleshGreen = patch(hAxe, ...);hYellow = patch(hAxe, ...);hRed = patch(hAxe, ...); % Add legendlegend(hAxe, [hGreen hYellow hRed], {'Green', 'Yellow', 'Red'}) Related QuestionContour on a contourf plotHow to use spline for a fig. fileExtract scattered data from figPlotyy legend for multiple lines ( R2012a)Error in XData=get(get(gca,’children’),’XData)How to setup legend for a figure with two axes (left and right)
Best Answer