필터 지우기
필터 지우기

Why same varible shown twice in Simulation Manager with parsim ?

조회 수: 1 (최근 30일)
Hainan Wang
Hainan Wang 2020년 10월 18일
댓글: Rahul Kumar 2021년 1월 11일
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
Rahul Kumar
Rahul Kumar 2021년 1월 11일
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));

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by