Using Objective Function with .mat File I/O for Parallel Computing
3 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Problem-Based Optimization Setup in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!