Using Objective Function with .mat File I/O for Parallel Computing

조회 수: 5 (최근 30일)
Rajmohan
Rajmohan 2019년 12월 12일
Hey Everyone!
I am working on an optimization problem which uses a complied Simulink model. The output of a simulink model is a .mat file that needs to be read and processed to create the output of the objective function. See code:
function y=costfunction(x,rtpstruct,mdlname,Tend)
% Change the tunable variable
rtpstruct=rsimsetrtpparam(rtpstruct,'ini',x);
save Rsim_Params rtpstruct
% Run Model
runname = ['.',filesep,mdlname,' -p Rsim_Params.mat -i Rsim_Input.mat -tf ',num2str(Tend),' -v '];
[~,~] = system(runname);
% Extract Simulation Parameters
simout = RsimOut(mdlname); % RsimOut load the .mat file and creates a more readable output.
% Output to minimize
y=sum(diff(simout.OutSig1));
end
This code generates an error when 'UseParallel' is set to 'true' in fmincon. I believe there is caused due to the fact that all the works are storing the data at the same location. Is there a way to fix this issue?
Thanks :)

답변 (0개)

카테고리

Help CenterFile Exchange에서 Manual Performance Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by