MATLAB R2024a is now available, and a lot of new important features have been added to Simulink. Here are my top 5.
Simulation object
Using the Simulation object, you can programmatically run a simulation step by step. You can execute the simulation one step at a time, for a specified number of steps or up to a specific time. Here is an example where I simulate the model up to t=18.5 seconds, then I change the value of variable k and continue the simulation until the stop time: % Run the first part of the simulation with k=0.2
% Run the second half with k=1.5
Design Study
The new Design Study API provides a layer on top of parsim and batchsim to improve scalability. Instead of creating an array of Simulink.SimulationInput objects, you specify arrays of values to be simulated, and how they should be combined. Here is a simple example where I simulate a mass-spring-damper system for different mass and damping values. I specify 5 mass values and 5 damping values, and simulate an exhaustive combination for a total of 25 simulation
kVar = simulink.multisim.Variable('c',1:5);
cVar = simulink.multisim.Variable('m',1:5);
fullSpace = simulink.multisim.Exhaustive([kVar cVar]);
myDesignStudy = simulink.multisim.DesignStudy(mdl, fullSpace);
outH = parsim(myDesignStudy,'ShowProgress','Off','UseFastRestart','on');
out = fetchOutputs(outH);
Specifying Variant Configurations using a SimulationInput object
A new VariantConfiguration property has been added to the Simulink.SimulationInput object. Here is an example code where I get the variant configuration data for a model and run one simulation per available configuration: mdl = 'sldemo_variant_subsystems';
load('variantConfigs.mat'); % load pre-saved variant configuration data
vcd = Simulink.VariantManager.getConfigurationData(mdl);
N = length(vcd.Configurations);
in(1:N) = Simulink.SimulationInput(mdl);
in(i) = in(i).setVariantConfiguration(vcd.Configurations(i).Name);
out = sim(in,'ShowProgress','off');
Simplified Mechanism to access Data Dictionaries
Before R2024a, if you wanted to programmatically change the value of a parameter stored in a data dictionary, you had to write code like this:
myDictionaryObj = Simulink.data.dictionary.open('simplesystemDD.sldd');
dDataSectObj = getSection(myDictionaryObj,'Design Data');
kObj = getEntry(dDataSectObj,'k');
In R2024a, you can simple connect to a data dictionary and interact with it using the dot operator. h = Simulink.data.connect('simplesystemDD.sldd');
Preserve alignment when moving and resizing blocks
Let's close this list with a simple quality-of-life editing improvement. This is not a game-changer like some of the previous highlights but will hopefully improve your editing experience.
When selecting a block, you might notice a light green highlighting on connections and blocks around it. This means that we have detected that those connections and blocks should likely move with the blocks.
Same works with resizing:
Now it's your turn
评论
要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。