Finding minimum output value for same inputs in a table
2 次查看(过去 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!