- Omit the useless "count=count+1;"
- Do you really mean total(m:n)=total_movement, or total(m, n) = ...?
- Is total pre-allocated? If not, search in this forum for "pre-allocation".
Can matlab not perform 115880 iterations fast?its taking hours to save the result of all iterations..how to iterate over all combinations and get results in minimum time
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have an array all_comb_ofRoutes=<1x64 cell> and onother array allCell_array=<1x1806 cell> I am doing multiplication of each elements using this code
[r2,c2]=size(all_comb_ofRoutes)
count=1;
for m=1:c2
for n=1:numel(allCell_array)
movement=(all_comb_ofRoutes{m})*allCell_array{n};
movement=movement>0;
total_movement=sum((sum(movement,2))-1);
count=count+1;
total(m:n)=total_movement
end
end
minValue=min(total)
[all_comb_ofRoutes(m) combination_array(n) allCell_array(n) minValue]
I want to store values of all iterations to get the minimum out of them but its taking very long time. how can I speed up this code? anyone please suggest me improvements
the complete code is given below
tic;
no_of_machines=7;
no_of_cells=3;
No_of_Parts=6;
P1=[1 0 0 1 0 1 1];
P2=[0 1 1 1 0 0 1];
P3=[1 0 0 1 1 0 0];
P4=[1 0 0 0 1 0 1];
P5=[1 1 0 0 0 1 0;1 1 0 0 1 0 1];
P6=[0 1 0 0 0 1 1;1 1 0 1 0 1 0];
P=vertcat(P1,P2,P3,P4,P5,P6);
n= 2^2-1;
all_comb_ofRoutes = zeros(No_of_Parts,size(P1,2),n+1);
for i=0:n
all_comb_ofRoutes(:,:,i+1) = P((1:1:6)+(dec2bin(i,No_of_Parts)-'0'),:);
end
all_comb_ofRoutes = cell(1,n+1);
for j=0:n
all_comb_ofRoutes{j+1} = P((1:1:6)+(dec2bin(j,No_of_Parts)-'0'),:);
end
C = zeros(no_of_cells^no_of_machines,no_of_machines);
t = 0;
for k = 0:(no_of_cells^no_of_machines)-1
s = dec2base(k,no_of_cells,no_of_machines);
if length(unique(s))==no_of_cells
t = t+1;
C(t,:) = s-'0'+1;
end
end
C = C(1:t,:);
combination_array=num2cell(C,2);% all possible combinations
%generating machine/cell matrix for above combinations
[r1,c1]=size(combination_array)
for l=1:r1
R=1:numel(combination_array{l});
Z = zeros(R(end),max(combination_array{l}));
Z(sub2ind(size(Z),R,combination_array{l})) = 1;
allCell_array{l}=Z; % machine cell matrix array of whole population
end
%calculating total movements
[r2,c2]=size(all_comb_ofRoutes)
count=1;
for m=1:c2
for n=1:numel(allCell_array)
movement=(all_comb_ofRoutes{m})*allCell_array{n};
movement=movement>0;
total_movement=sum((sum(movement,2))-1);
count=count+1;
total(m:n)=total_movement
end
end
minValue=min(total)
[all_comb_ofRoutes(m) combination_array(n) allCell_array(n) minValue]
toc;
I need help in changing code for last potion % calculating total movements
0 Kommentare
Antworten (2)
Jan
am 13 Jan. 2017
total = zeros(c2, numel(allCell_array));
for m = 1:c2
for n = 1:numel(allCell_array)
movement = all_comb_ofRoutes{m} * allCell_array{n};
total(m, n) = sum(sum(movement > 0, 2)) - size(movement, 1);
end
end
2 Kommentare
Steven Lord
am 13 Jan. 2017
Run your code in the MATLAB Profiler using a subset of the data from your larger cell arrays -- for instance, run your code using the first 10 or 20 cells in each cell array. Use the Profiler output (and any suggestions provided by Code Analyzer in the Editor window) to identify the bottlenecks in your code and potentially ways to improve those bottlenecks.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!