필터 지우기
필터 지우기

how to fix error in selecting minimum value from iteration matrix?

조회 수: 3 (최근 30일)
summyia qamar
summyia qamar 2017년 1월 14일
답변: Niels 2017년 1월 14일
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
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Niels
Niels 2017년 1월 14일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by