필터 지우기
필터 지우기

Optimize based on on max min of columns

조회 수: 1 (최근 30일)
Thomas
Thomas 2016년 5월 10일
댓글: Stephen23 2016년 5월 10일
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