Hi
I'm doing a Brute Force search by varying 5 parameters, running a Simulink model and then calculating a cost function.
I have a Matlab script which contains the following:
simTime = 2;
N = 5;
brakeRange = 0:1/(10-1):1;
timeVec = 0:simTime/(N-1):simTime;
leng = length(brakeRange);
data = zeros(leng^N,N+1);
a =1;
tic
for i = 1: leng
s = sprintf('\n Percentage complete = %s % ',num2str((a/leng^N)*100));
disp(s);
for j = 1: leng
for k = 1: leng
for l = 1: leng
for m = 1: leng
inVec = [brakeRange(i) brakeRange(j) brakeRange(k) brakeRange(l) brakeRange(m)];
simOut = sim(mdl,'SimulationMode','Accelerator','ReturnWorkspaceOutputs', 'on');
tempJ = simOut.get('cost');
data(a,:) = horzcat(tempJ(end), inVec);
a = a +1;
end
end
end
end
end
Unfortunately, the code is very slow, so I decided to purchase the Parallel Computing Toolbox. I tried to use Parfor, but I get the error message "the PARFOR loop cannot runt due to the way data is used." I get the same message for the variable 'a'.
I think the problem has to do with sliced variables (?) but I'm not sure as I'm new to Parallel Computing. How does one implement parfor loops with nested for loops?
0 Comments
Sign in to comment.