Finding minimum output value for same inputs in a table
조회 수: 5 (최근 30일)
이전 댓글 표시
I am a new user of matlab and have a question about tables.
So I have a table called myTable with three different inputs (x,y,z) and one output (fct_total), for some of the inputs I sometimes have different outputs (see higlighted rows in screenshot)
I wonder if there is any way using for example logical indexing to select the smallest output (fct_total) in the cases where inputs are the same and then place the inputs and the minimum value of the output in a separate table?
댓글 수: 0
채택된 답변
Scott MacKenzie
2022년 3월 28일
Is your table consistently organized as in the image; i.e., 36 rows repeating with the same values execpt for the last column (fct_total)? If so, this code will create a column vector containing the miminum values in the fct_total column for each x-y-z combination:
d = reshape(myTable.fct_total, 36, []);
min_d = min(d, [], 2);
Then, create a new table using the min_d values and the x-y-z combinations.
추가 답변 (1개)
Davide Masiello
2022년 3월 28일
편집: Davide Masiello
2022년 3월 28일
clear,clc
% The following matrix has two rows which have same x-y-z but different
% output (namely, first and last rows)
A = rand(9,4);
A = [A;A(1,:)];
A(end,end) = A(1,end)*2
% Extract the smallest of the two values
xyz = A(1,1:3); % This is the input that has two possible outputs
output = min(A(all(A(:,1:3)==xyz,2))) % Mimimum output
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!