Parfor loop for simulink

1 次查看(过去 30 天)
Rashmil Dahanayake
Rashmil Dahanayake 2014-5-16
HI, I'm trying to run a simulink model from parfor loop. However the output generated from the loop seems to be identical when input variables changed.
I simulated this using sim command and for loop. The output is as expected. Could someone please help me to correct the parfor script.
Simulink and matlab scripts attached.
Parfor loop code:
%' M-File script to plot simulation data '
%%Load System
clc;clear all;
% load_system('sine'); % move to parfor loop
%%Define Parameter sets
Volts = (1:2:20); % set voltage amplitude;
f = 2 ; % set simulation values for 2hz
iterations=numel(Volts);
simout =cell(1,iterations);
%%Run the sim command
tic
parfor k = 1:iterations
load_system('sine');
set_param('sine/Amplitude','Gain', num2str(Volts(k)));
%sim('sine', [0 1.1]); % run simulation sine.slx set simulation time 0<t<2
simout{k}=sim('sine');
end
toc
working for loop
%' M-File script to plot simulation data '
clc;clear all;
load_system('sine'); % move to parfor loop
Volts = (1:2:20); % set voltage amplitude;
f = 2 ; % set simulation values for 2hz
iterations=numel(Volts);
for k = 1:iterations
set_param('sine/Amplitude','Gain', num2str(Volts(k))); % set f value for simulation
sim('sine', [0 1.1]); % run simulation sine.slx set simulation time 0<t<2
vc(k,:) = yout(:,1); % save capacitor voltage data
end
plot(tout,vc(1,:),tout,vc(2,:),tout,vc(3,:)); % values to plot
xlabel('Time (secs)'); grid;
ylabel('Amplitude (volts)');
st1 = 'F = ';
st2 = num2str(f); % convert V value to string
st3 = ' Hz'; % Greek symbol for Ohm
st4 = ', V = ';
st5 = num2str(Volts(1));
st6 = ' Volts';
sl1 = strcat(st1,st2,st3,st4,st5,st6); % legend 1
st5 = num2str(Volts(2));
sl2 = strcat(st1,st2,st3,st4,st5,st6); % legend 2
st5 = num2str(Volts(3));
sl3 = strcat(st1,st2,st3,st4,st5,st6); % legend 3
title('Voltage Plot Using SIM')
legend(sl1,sl2,sl3);

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 View and Analyze Simulation Results 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by