MATLAB Answers

0

Modeling a resistor using custom Simscape block and lookup tables using data from an excel sheet.

Asked by Pranav Ananthakumar on 1 Mar 2019
Latest activity Answered by Zeng
on 17 Apr 2019
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 Comments

Sign in to comment.

Products


Release

R2018a

1 Answer

Answer by Zeng
on 17 Apr 2019

In my opnion, you should read the file in "Setup".

  0 Comments

Sign in to comment.