Optimize based on on max min of columns

1 次查看(过去 30 天)
Hi,
I have an array where each row indicates the parameters of an item, I want to set constraints for each column (or parameter) and find the optimum item that closely meets these parameters. Here is an example,
%
A = [80 7.5 1000 0.5;120 500 3000 1;50 256 500 0.5];
For the first column I want the maximum, for the second I want the minimum, the third I want the max and the fourth I want the max. However as each row represents an item I need the item which closely matches the parameters I set. So far I have been trying to use a logic array that gives a 1 where the max/min value is and a zero where it does not meet the criteria then summing each row and the highest number will give the optimum. I have been trying to use a for loop to go through each column but I am having difficulty selecting both maximum and minimum across the array. So I would end up with an array like this,
%
A1 = [0 1 0 0;1 0 1 1;0 0 0 0]
The logical array indicates that the 2nd column is the optimum. If anyone has any advice on how to proceed, I would be very grateful.
  1 个评论
Stephen23
Stephen23 2016-5-10
"indicates that the 2nd column is the optimum"
presumably you mean row, not column.

请先登录,再进行评论。

回答(1 个)

Stephen23
Stephen23 2016-5-10
编辑:Stephen23 2016-5-10
With MATLAB using a loop to solve this is a waste of time. Try something like this:
>> A = [80 7.5 1000 0.5;120 500 3000 1;50 256 500 0.5]
A =
80 7.5 1000 0.5
120 500 3000 1
50 256 500 0.5
>> vec = max(A,[],1);
>> vec(2) = min(A(:,2))
vec =
120 7.5 3000 1
>> idx = bsxfun(@eq,A,vec)
idx =
0 1 0 0
1 0 1 1
0 0 0 0
>> [~,row] = max(sum(idx,2))
row = 2

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by