MATLAB nested loop

Job ID: 33389500

Budget: $10 – $30 USD

Hi, I have a MATLAB function includes several nested loops. My function, finally will have 14 nested loops and computational effort will be unacceptable. Looking for an alternative way to produce a 14 D matrix without using nested loops. Following function shows only 4 nested loops:
I also need to reproduce the same function in Python.


function matrix = core_mapFBVolume(sampling, ram, ptdf)

nbPoints = length(sampling);
matrix = false(nbPoints,nbPoints,nbPoints,nbPoints); % four dimentional domain since there is five countries, change to more if more countrieas are added

nhubs = size(ptdf,2);
netHubPositions = zeros(nhubs,1);

for k1 = 1:nbPoints
netHubPositions(1) = sampling(k1);
for k2 = 1:nbPoints
netHubPositions(2) = sampling(k2);
for k3 = 1:nbPoints
netHubPositions(3) = sampling(k3);
tmp = -sampling(k1)-sampling(k2)-sampling(k3);
for k4 = 1:nbPoints
netHubPositions(4) = sampling(k4);
netHubPositions(5) = tmp -sampling(k4);
matrix(k1,k2,k3,k4) = all(ptdf*netHubPositions <= ram);
end
end
end
end
end
Related categories: Python Matlab and Mathematica