for i=1:1:k %k = 100 people
for j=1:1:l %l = 5 orders
Resultx = a + b + d(j); % cost of drink Resultx
Resulty = f + g + c(j); % cost of food Resulty
end
Matrix(i) = [Resultsx1...j Resulty1...j]
end
これら% notes
は、解決したい問題を頭の中で表現し、後でスクリプトで表現するのに役立ちます。
for eachi
が注文した飲み物と食べ物のコストのマトリックスに値を格納したいとしましょう。
だから人にとってi = 1
、
1[1 5] %people 1, first order: drink costs 1 and food costs 5
2[2 3] %people 1, second order: drink costs 2 and food costs 3
...
j[x y] %people 1, j order: drink and food costs x and y
!!! Matrix(1) = sort (j [x,y]) !!!
人のためi = 2
に、
1[1 5] %people 2, first order: drink costs 1 and food costs 5
2[2 3] %people 2, second order: drink costs 2 and food costs 3
...
j[x y] %people 2, j order: drink and food costs x and y
!!! Matrix(2) = sort (j [x,y]) !!!
人のためi = k
に、
1[1 5] %people k, first order: drink costs 1 and food costs 5
2[2 3] %people k, second order: drink costs 2 and food costs 3
...
j[x y] %people k, j order: drink and food costs x and y
!!! Matrix(i) = sort (j [x,y]) !!!
i
各反復のすべての結果を行列に昇順で形成したい
Matrix(i) = sort (j [x,y]).
最適なパラダイムではないかもしれませんが、よろしくお願いします。