How to calculate average function with multiple functions

20 次查看(过去 30 天)
I'm trying to create an average battery discharge line as a function of SOC with multiple data sets.
The discharge data plotted in the file 'ICR1865022P_Testdata.mat' will give the figure above. Now what I want is to calculate an average discharge curve that will be used for further calculations of the battery discharge Voc.
I'm attaching the measurement data and an .m file to properly display the problem. In the .m file provided I've taken the discharge curve of 'LoadV_discharge5' as an example but the plan is to use the calculated average from there on. I think the bump in the road, for me, is the different lengths of the data sets. This is preventing me of calculating an average out of the data sets. In my mind the only way to create an average functions is to calculate functions out of every data set and then calculate an average function out of those functions.. Its kinda difficult to explain so if I'm leaving any info out, please let me know!
Kind regards,
Michel.

采纳的回答

Star Strider
Star Strider 2015-12-6
I’m not certain what plot I’m looking at in your Question. I could not figure out how to reproduce it in my code, so I will let you plot it.
I did manage to interpolate and then take the means and standard deviations what I believe to be the variables you are interested in. If they are not, my code should at least provide a way for you to do the interpolations and other calculations on the correct variables. I used the longest ‘t_discharge’ vector as the basis of the interpolation, so the ‘LoadV_discharge’ vectors (matrix) are all interpolated to the same times, that being ‘t_discharge{Idx}’.
The code:
load('Michel de Jongh ICR1865022P_Testdata.mat'); % Load Data Into Workspace
vars_t_d = whos('t_discharge*'); % Get ‘t_discharge’ Names
vars_LV_d = whos('LoadV_discharge*'); % Get ‘LoadV_discharge’ Names
for k1 = 1:length(vars_t_d)
t_discharge{k1} = eval(vars_t_d(k1).name); % Create ‘t_discharge’ Cell Array
LoadV_discharge{k1} = eval(vars_LV_d(k1).name); % Create ‘LoadV_discharge’ Cell Array
vctlen(k1) = length(t_discharge{k1}); % Vector Lengths
end
[LenMax,Idx] = max(vctlen); % Longest Vector & Index
for k1 = 1:length(vars_t_d) % Interpolation Loop
LoadV_disch_intrp(:,k1) = interp1(t_discharge{k1}, LoadV_discharge{k1}, t_discharge{Idx}, 'spline', 'extrap');
end
figure(1)
plot(t_discharge{Idx}/3600, LoadV_disch_intrp)
grid
LoadV_disch_mean = mean(LoadV_disch_intrp, 2); % Column Vectors, So Take Means Across Rows
LoadV_disch_std = std(LoadV_disch_intrp, [], 2); % Column Vectors, So Take Standard Deviations Across Rows
figure(2)
plot(t_discharge{Idx}/3600, LoadV_disch_mean, '-r')
hold on
plot(t_discharge{Idx}/3600, LoadV_disch_mean+1.96*LoadV_disch_std, '-g')
plot(t_discharge{Idx}/3600, LoadV_disch_mean-1.96*LoadV_disch_std, '-g')
hold off
grid
I apologise for the delay. I was doing my best to reproduce your plot to check my calculations, and cannot figure out what you are plotting. (I used your code as a basis for mine, but did not run it.) The benefit of my code is also that it creates a matrix of your dynamically-named variables and then does all the calculations on the matrix. You might also find a 'linear' interpolation to be preferable to 'spline'.
I would retain the 'extrap' option in the interp1 call regardless. (It requires that you specify a method.) It will avoid errors if your ‘t_discharge’ variables do not all begin and end at the same times.
  5 个评论
Star Strider
Star Strider 2015-12-8
Thank you. My pleasure!
I enjoy helping with research data analysis problems because I feel I’m actually doing something. Yours was one of the most complicated and challenging I’ve ever encountered! I’m learning a lot as well.
One item I thought of is to create a vector from your independent variable to make the code a bit easier to read:
PctCharge = [100:-(100/(size(LoadV_disch_intrp(:,1),1)-1)):0];
The interpolated variable length is the same for all the interpolated vectors, so one size now fits all. Rename it to represent what it actually is — I called it ‘percent charge’ because I don’t know what it is.
imposterimposter
imposterimposter 2017-12-5
编辑:imposterimposter 2017-12-5
Hi there,
I came across this old thread which luckily addresses exactly what I am struggling with. The only issue is that I was hoping to inspect Michel's .mat file to see how exactly he organized his data. I know how to load the file into my script but not sure how to actually open the file and look at the content.
Thanks in advanced!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by