Clear Filters
Clear Filters

Error using Battery.lo​adDataFrom​MatFile Unable to locate voltage variable in file '03-11-17_08.47 25degC_5Pu​lse_HPPC_P​an18650PF.​mat'

4 views (last 30 days)
Hey everyone. I just run the Example_DischargePulseEstimation.m code which is prepared code from MATLAB. To run the code I wrote this to command
open('Example_DischargePulseEstimation.m')
and clicked enter.It worked but I want to use this code for another "*.mat" data file.So I just copy paste a code and adapt it to my data but MATLAB constantly gives error.
The Code That I used for Another data:
psObj = Battery.PulseSequence;
disp(psObj)
FileName = '03-11-17_08.47 25degC_5Pulse_HPPC_Pan18650PF.mat';
[time,voltage,current] = Battery.loadDataFromMatFile(FileName);
addData(psObj,time,voltage,current);
The Error It's given:
Error using Battery.loadDataFromMatFile
Unable to locate voltage variable in file '03-11-17_08.47 25degC_5Pulse_HPPC_Pan18650PF.mat'
Error in Battery.loadDataFromMatFile Error in kod3 (line 33)
[time,voltage,current] = Battery.loadDataFromMatFile(FileName);
I used the data from Mendeley data: https://data.mendeley.com/datasets/wykht8y7tg
The data in code is in attached file!!

Answers (1)

Gowthami
Gowthami on 22 Nov 2022
Hello Hanife,
It is my understanding that you are getting an error while loading data from MAT file.
I could see that executing the below command returning 'meas: [1×1 struct]' ,
open '03-11-17_08.47 25degC_5Pulse_HPPC_Pan18650PF.mat'
All the fields are present inside the meas struct, Because of this you are getting error as 'Unable to locate voltage variable in file '03-11-17_08.47 25degC_5Pulse_HPPC_Pan18650PF.mat''
The function 'Battery.loadDataFromMatFile(FileName)' is expecting the filed names as current, time, and voltage as shown in the below image,
Please refer to the below link for more information on saving a few specific fields into a MAT file - https://www.mathworks.com/help/matlab/import_export/load-parts-of-variables-from-mat-files.html
  1 Comment
Hanife Güney
Hanife Güney on 26 Dec 2022
Thank you so much. I solved the problem with this code below:
clear all
close all
psObj = Battery.PulseSequence;
files = '06-15-17_11.31 n20degC_5Pulse_HPPC_Pan18650PF.mat';
load(files);
fields = ["TimeStamp","Wh","Power","Battery_Temp_degC","Chamber_Temp_degC"];
meas = rmfield(meas,fields);
meas = struct2cell(meas);
meas=cell2mat(meas);
voltage=meas(1:49655,:);
current=meas(49656:99310,:);
Ah=meas(99311:148965,:);
Time=meas(148966:198620,:);
time=Time;
% psObj.addData(Time,Voltage,Current);
psObj.Data(1:49655,1) = time;
psObj.Data(1:49655,2)=voltage;
psObj.Data(1:49655,3)=-current;
psObj.Data(1:49655,4)=Ah;
psObj.Data(1:49655,5)=1-(-Ah/2.9);
psObj.plot()
As you said I convert meas to struct then convert to cell and it worked.

Sign in to comment.

Categories

Find more on Powertrain Reference Applications in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!