how to fix error in selecting minimum value from iteration matrix?
显示 更早的评论
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;
2 个评论
Image Analyst
2017-1-14
Undefined function or variable 'allcomb'.
Error in test1 (line 15)
a = allcomb(1:z(1),1:z(2),1:z(3),1:z(4),1:z(5),1:z(6));
You forgot to give us allcomb(). Or, if it's in one special toolbox, then you forgot to list what toolbox(es) is/are required to run your code.
summyia qamar
2017-1-14
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!