Why same varible shown twice in Simulation Manager with parsim ?

1 visualización (últimos 30 días)
Hainan Wang
Hainan Wang el 18 de Oct. de 2020
Comentada: Rahul Kumar el 11 de En. de 2021
I want to perform a parametric sweep with parsim. The variable I want to sweep is t0, the ‘Start Time’ in Simulink model, from 0 to 1 with intervals of 0.1. Other variables are loaded from external .mat file. In this .mat file, t0 is set to 0 and there are no ‘upars’’ and vpars’ variables in it. The Simulink model input_checkN1P10test1.slx’s model workspace is empty and has no Data source. When I ‘parsim’ the SimulationInput object ‘simin’, the variable ‘t0’ shown in Simulation Manager has two different values for each simin, 0 (which I think is from .mat file) and t0 values I set with SetVariable method. Judging from the output, Simulink indeed uses the t0 values set with setVariable method when I create ‘simin’ but my puzzle is why there are still two values shown in Simulation Manager?
clear all
mdl = 'input_checkN1P10test1'; % mdl has no vars in model ws and data source
N = 10;
tset = linspace(0,1,N+1);
simin(1:N) = Simulink.SimulationInput(mdl);
load_system(mdl)
hws1 = get_param(mdl,'modelworkspace')% should be empty
for i = 1: 10
simin(i) = simin(i).loadVariablesFromMATFile('inputpars_simulink.mat');
simin(i) = simin(i).setVariable('t0',tset(i),'workspace','input_checkN1P10test1');
simin(i) = simin(i).setVariable('upars',50*ones(1,10),'workspace','input_checkN1P10test1');
simin(i) = simin(i).setVariable('vpars', 5*ones(1,10),'workspace','input_checkN1P10test1');
end
simout1 = sim(simin);%
simout2 = parsim(simin,'ShowSimulationManager','on');%
  1 comentario
Rahul Kumar
Rahul Kumar el 11 de En. de 2021
Hi Hainan,
My guess is that you have t0 defined in both the model workspace and global workspace on the SimulationInput object which is why it appears twice. Try using the following code instead and see if that fixes it (removing the Workspace value with setVariable defaults to global workspace)
simin(i) = simin(i).setVariable('t0',tset(i));

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Simulink Environment Customization en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by