Sort an array while keeping the right index

3 ビュー (過去 30 日間)
Jennifer Pettersson
Jennifer Pettersson 2019 年 5 月 22 日
回答済み: Steven Lord 2019 年 5 月 22 日
aHi!
My problem is that I want to "fill" the biggest factory with as many customers demand as possible and when that factory is full, I want to proceed to the next factory and so on.. The goal is to end up with the approximately (!) lowest cost
I have an idea of sorting the arrays like this to solve the problem but is it possible to sort s & d while keeping the right index in f & c?
Before
m = 3; %Number of possible locations
n = 5; %Number of customers
s = [ 225 184 239 ] ; %factory storage limit
d = [ 92 82 83 69 74 ] ; %demand each customer
f = [ 886 766 589]; % fixed cost
c = [ 9 22 26 5 21 %transportation cost from each factory to each customer
16 11 23 28 24
14 5 6 24 6 ];
After
m = 3;
n = 5;
s = [ 239 225 184 ] ; %decending
d = [ 69 74 82 83 92 ] ; %ascending
f = [ 589 766 886 ];
c = [ 14 5 6 24 6
9 22 26 5 21
16 11 23 28 24 ];
Or is there another smarter way? Should I instead try to take the highest/lowest value (something like max(s) and min(d) ?, but then again how to I do when I in the next step need the "second highest/lowest" value?
(Yes, it is a school assignment, I just want guidelines)
  1 件のコメント
madhan ravi
madhan ravi 2019 年 5 月 22 日
Have you looked at sort() function?

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2019 年 5 月 22 日
Look at the second output from the sort function. That can be used to generate the first output of sort from the input array, but it is not limited to being used only on that input array.

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by