How to calculate mean square error, i'm using mean(x) function but its giving NaN value. i have also attached my code below.

clear all; clc;
load('UDDSprofile.mat')
Time = UDDSprofile(2:end,2)' - UDDSprofile(2,2);
U = UDDSprofile(2:end,3)';
Vt_exp = UDDSprofile(2:end,4)';
ode_fun=@(t,y) BATTERY(t,y,Time,U);
[T,Y] = ode45(ode_fun,[0 3500],[0.7 0 0]);
x1=Y(:,1); x2=Y(:,2); x3=Y(:,3);
u = interp1(Time,U,T);
load('HPPC_parameters.mat');
r0 = interp1(SOC,R0,x1);
V_out =-r0.*u+ boc(x1)-x2-x3;
V_exp=interp1(Time,Vt_exp,T);
%RMSE
E = (V_exp - V_out);
SE = E.^2;
MSE = mean(SE);
RMSE = sqrt(mean((V_exp - V_out).^2));

2 Kommentare

Unfortunately we do not have your mat files so we cannot test.
u = interp1(Time,U,T);
Instead of doing that, you can pass in U as the tspan (provided it is in sorted order) instead of passing in [0 3500] . When you pass in a vector with more than 2 entries as the tspan then MATLAB will report back for exactly those locations only, making it unnecessary to interpolate afterwards.
It can be a bit cavalier to immediately leap to the
mean(y,'omitnan')
solution, without understanding the reason why the NaNs are in the data. It seems more likely to me that the existence of NaNs in SE (and therefore in E, and therefore in either V_exp or V_out, etc.) is the problem.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Gefragt:

am 11 Mär. 2023

Kommentiert:

am 12 Mär. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by