How to modify Mass in EvReferenceApplication to be "Mass + adder"?

1 次查看(过去 30 天)
I'm trying to use the EvReferenceApplication mostly as-is, as a starting point for evaluating the impact of adding things to the vehicle.
Using Mass as an example, what I would like to do is maintain a separate "MassAdder" variable that accumulates all of the weights I'm adding. When the Vehicle Simulation is run, I would like it to use "Mass + MassAdder" wherever it currently uses "Mass" as a parameter.
This is more of an editor/scripting/workspace question.
Is there an easy way to modify EvReferenceApplication to make this substitution?
Thanks!

回答(1 个)

Akshat Dalal
Akshat Dalal 2023-12-24
编辑:Akshat Dalal 2023-12-26
Hi Mark,
I understand that you want to modify the 'EvReferenceApplication' to accumulate all the individual weights into a single variable 'MassAdder' and then replace the individual weights with the sum of that weight and 'MassAdder'.
This is possible and you could do it using the following approach:
  • Create variables 'Mass1', 'Mass2', 'Mass3', etc., in the MATLAB base workspace, each assigned to the value of an individual weight. Then, configure your model to use these variables instead of hardcoded weight values or other variables.
  • Initialize 'MassAdder' with 0 and then find all variables in base workspace of the form 'Mass1', 'Mass2', 'Mass3', etc., and accumulate them in 'MassAdder'. You could use the following script to do so:
MassAdder = 0;
Masses = who('-regexp', 'param');
for i = 1:length(Masses)
Mass = evalin("base", Masses{i});
MassAdder = MassAdder + Mass;
end
  • Find all blocks in the model which reference the individual mass variables and then replace these with the variable 'Mass1 + MassAdder'. You could find and modify the blocks by tweaking the following script:
% Set the name of your model
modelName = 'EvReferenceApplication'; % Replace with your model name
% Load the model into memory (without opening the UI)
load_system(modelName);
% Find all blocks in the model
allBlocks = find_system(modelName, 'Type', 'Block');
% Loop through all blocks and check their parameters
for i = 1:length(allBlocks)
block = allBlocks{i};
blockHandle = get_param(block, 'Handle');
blockVal = get(blockHandle); % Use this to check and modify the block parameters if
% they use Mass values. You could also use get_param/set_param on the block.
end
Hope this helps!

类别

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

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by