Modeling a resistor using custom Simscape block and lookup tables using data from an excel sheet.
조회 수: 2 (최근 30일)
이전 댓글 표시
Hey, I am trying to model a resistor but whenever I try to read the specific columns from the excel sheet, Matlab gives an error 'Invalid use of non-parametric value 'Data'. All entities referenced in member declarations must be parameters'. I have specified the excel file in the same folder as the .ssc file. My execution steps are correct, there is only something wrong with my code. I am affixing the code below, can you pls rectify it. I have commented the error. I am also attaching the excel file 'Battery_Parameters.xlsx'. Pls fix any other errors if you feel so and give feedback if I'm doing anything wrong.
Code:
component Cell
nodes
p = foundation.electrical.electrical; %+:left
n = foundation.electrical.electrical; %-:right
end
variables
i = {0,'A'};
v = {0,'V'};
SOC = {0,'Pa'}; % Provided simply as a unit is required
Data = xlsread('Battery_Parameters.xlsx');
R_Discharge = {0,'Ohm'}; % resistance
end
parameters (Size=variable)
xd = Data(2:end,1) %Error
yd = Data(2:end,4) %Error
end
function setup
if R_Discharge<0
pm_error('simscape:GreaterThatOrEqualToZero','Resistance')
end
end
branches
i: p.i -> n.i;
end
equations
v == p.v - n.v;
R_Discharge == tablelookup(xd, yd, SOC, interpolation=linear, extrapolation=nearest);
end
end
댓글 수: 0
답변 (2개)
Pramil
2024년 10월 17일
Hi Pranav,
For loading external data in a SSC file you can use "MATLAB Declaration Functions". Here is the link for the following:
Here is the updated code that works in both MATLAB R2024a as well as R2018a:
component Cell
nodes
p = foundation.electrical.electrical; %+:left
n = foundation.electrical.electrical; %-:right
end
variables
i = {0,'A'};
v = {0,'V'};
SOC = {0,'Pa'};
R_Discharge = {0,'Ohm'}; % resistance
end
parameters (Access = private)
[xd,yd] = my_fcn();
end
branches
i: p.i -> n.i;
end
equations
assert(R_Discharge>=0);
v == p.v - n.v;
R_Discharge == tablelookup({xd 'Pa'}, {yd 'Ohm'}, SOC, interpolation=linear, extrapolation=nearest);
end
end
Where "my_fcn" is:
function [xd,yd] = my_fcn()
Data = xlsread('Battery_Parameters.xlsx');
xd = Data(2:end,1);
yd = Data(2:end,4);
end
Hope it helps.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Choose and Parameterize Blocks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!