How to calculate 2 signals errors from excel datasheets?

Hi,
I have 6 excel datasheets, each sheet contains 5 data signals. each data signals contains (measured (x,y) and calculated fits (x,y) data), which measured in different locations.
I need to calculate the errors (mean, standard deviation, root mean square) between the measured and calculated data. Then get the average of all errors of all 5 data signals
ex: datasheet 1 signal 1 mean error = 2 signal 2 mean error = 5 signal 3 mean error = 1 signal 4 mean error = 2.5 signal 5 mean error = 1.5
I want to get the average mean error of datasheet 1-6, separately.
Issue: measured data has a different range of calculated data and it has to be same data range to calculate the errors.
The code:
close all ; clear ; clc ; tic ;
filename = 'Cell_Error.xlsx'; % 5 Datasheets {HNC_2_07, HNC_2_09, HNC_2_10, U87_02, U87_03, U87_05} sheetnames = {'HNC_2_07'}; % Measured and Calculated Data xlRange = {'A3:E2135', 'G3:K2135', 'M3:Q2135', 'S3:W2135', 'Y3:AC2135' };% 'A3:B2135', 'G3:H2135', 'M3:N2135', 'S3:T2135', 'Y3:Z2135'};
n = length(sheetnames); m = length(xlRange);
figure(1); hold on data=zeros(1,1);
for idx = 1:n; idx; mn_tot =0; st_tot =0; Err_tot =0; SErr_tot =0; MSErr_tot = 0; RMSE_tot = 0;
for idl = 1:m;
idl;
data = xlsread(filename,sheetnames{idx},xlRange{idl});
Disp_Meas =data(:,1); % Measured Displacement 1nd column of the data
Force_Meas =data(:,2); % Measured Foece 2ed column of the data
Disp_Calc = data(:,4); % Calculated Displacement 4th column of the data
Force_Calc = data(:,5); % Calculated Force 5th column of the data
% NOTE: THERE ARE SOME NANS IN THE DATA. If you want to remove those, use
% isnan():
% Measured
badRows = isnan(Force_Meas); % Logical vector.
Disp_Meas = Disp_Meas(~badRows); % Extract good rows.
Force_Meas(badRows) = []; % Alternate way to remove, set bad rows equal to null.
% Calculated
badRows = isnan(Force_Calc); % Logical vector.
Disp_Calc = Disp_Calc(~badRows); % Extract good rows.
Force_Calc(badRows) = []; % Alternate way to remove, set bad rows equal to null.
% Interpolate Force_Calc y data so that it's estimated at the locations of the
% Disp_Meas x locations:
yCalcInterpolated = interp1(Disp_Calc, Force_Calc, Disp_Meas);
%yMeasInterpolated = interp1(Disp_Meas, Force_Meas, Disp_Calc);
% Least Squear Errors
mn = mean((Disp_Calc-Disp_Meas).^2) % Mean Error
st = std((Disp_Calc-Disp_Meas).^2) % Standred diviation Error
Err = (Disp_Meas - mn) % Errors
SErr = (Disp_Meas - mn).^2 % Squared Error
MSErr= mean((Err).^2) % Mean Squared Error
RMSE = sqrt(MSErr); % Root Mean Squared Error
% Add old error to the new error
mn_tot = mn_tot+ mn;
st_tot = st_tot+ st;
Err_tot = Err_tot + Err;
SErr_tot =SErr_tot + SErr;
MSErr_tot = SErr_tot + SErr;
RMSE_tot = SErr_tot + SErr;
% Plot them both at the Disp_Meas locations.
plot(Disp_Meas, Force_Meas, 'k.-', 'LineWidth', 2, 'MarkerSize', 10);
hold on;
% Plot fitted Calcualtion.
plot(Disp_Meas, yCalcInterpolated, 'r.-', 'LineWidth', 1, 'MarkerSize', 10);
%plot(Disp_Meas,Force_Meas,Disp_Calc,Force_Calc);
title('Force-Displacement Curve')
xlabel('Displacement [nm]')
ylabel('Force [nN]')
legend('Measured Data','Calculated Data')
end
% Average Errors
mn_average = mn_tot/m;
st_average = st_tot/m;
Err_average = Err_tot/m;
SErr_average =SErr_tot/m;
MSErr_average = SErr_tot/m;
RMSE_average = SErr_tot/m;
end

1 Comment

The curve of measure and calculated data look like this. Also, the picture of excel file is attached

Sign in to comment.

Answers (0)

Asked:

on 13 Jan 2018

Commented:

on 13 Jan 2018

Community Treasure Hunt

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

Start Hunting!