MATLAB: How to fix error in selecting minimum value from iteration matrix

errorMATLABminimum value from loop

I'm running this code. I want to have all iterations saved in Total_all matrix and from that matrix select the minimum value. then display the corresponding matrices in result which show minimum value. the code is below.but the code is giving minValue as a complete row. can any one please check this?
tic;
no_of_machines=7;
no_of_cells=3;
No_of_Parts = 6;
P1=[1 0 0 1 0 1 1;1 1 0 0 1 0 1];
P2=[0 1 1 1 0 0 1;1 0 1 0 1 1 0];
P3=[1 0 0 1 1 0 0;0 1 1 0 0 0 1];
P4=[1 0 0 0 1 0 1;0 1 0 1 0 1 0];
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 = [P1;P2;P3;P4;P5;P6];
z = [size(P1,1) size(P2,1) size(P3,1) size(P4,1) size(P5,1) size(P6,1)];
c = [0 cumsum(z(1:end-1))];
a = allcomb(1:z(1),1:z(2),1:z(3),1:z(4),1:z(5),1:z(6));
n = size(a,1);
all_comb_of_routes = cell(1,n);
for k=1:n
all_comb_of_routes{k} = P(c+a(k,:),:);
end
CELL = zeros(no_of_cells^no_of_machines,no_of_machines);
t = 0;
for k = 0:(no_of_cells^no_of_machines)-1 %k=(2187-1=2186)
s = dec2base(k,no_of_cells,no_of_machines);
if length(unique(s))==no_of_cells
t = t+1;
CELL(t,:) = s-'0'+1;
end
end
CELL = CELL(1:t,:);
combination_array=num2cell(CELL,2);% all possible 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;
allCells_array{l}=Z; % machine cell matrix array of all combinations
end
[r2,c2]=size(all_comb_of_routes);
total_all= zeros(c2, numel(allCells_array));
for m = 1:c2
for n = 1:numel(allCells_array)
movement = all_comb_of_routes{m} * allCells_array{n};
total=sum((sum(movement > 0, 2)) -1);
total_all(m,n) =total;
end
end
minValue=min(total_all)
[all_comb_of_routes(m) allCells_array(n) combination_array(n) minValue];
toc;

Best Answer

concerning your problem with the minimum:
check min
you can either use
minValue=min(total_all(:));
% if you want/ need the index:
[minValue,IndexminVal]=min(total_all(:));
or use the min command twice
minValue=min(min(total_all));
the result is the same