num_cols=length(data)
start_pf=[data{1,1}(1,1),data{1,2}(1,1),data{1,3}(1,1),data{1,4}(1,1),data{1,5}(1,1),data{1,6}(1,1)];
for i=1:1:num_cols
if i==1
iteration=[reshape(data{i},length(data{i}),1),repmat(start_pf(1,i+1:end),length(data{i}),1)];
else
iteration=[repmat(iteration(best1,1:i-1),length(data{i}),1),reshape(data{i},length(data{i}),1),repmat(iteration(best1,i+1:end),length(data{i}),1)];
end
for j=1:1:length(data{i})
y(j)=a(1,iteration(j,1)) + a(2,iteration(j,2)) + a(3,iteration(j,3)) + a(4,iteration(j,4)) + a(5,iteration(j,5)) + a(6,iteration(j,6)) ;
x(j)=function1(iteration(j,1),iteration(j,2),iteration(j,3),iteration(j,4),iteration(j,5),iteration(j,6));
z(j)=y(j) + y(j);
best1=find(z==min(z));
end
end_pf=iteration(best1,:);
end