Finding minimum output value for same inputs in a table
Show older comments
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?
Accepted Answer
More Answers (1)
Davide Masiello
on 28 Mar 2022
Edited: Davide Masiello
on 28 Mar 2022
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
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!