Finding minimum output value for same inputs in a table
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
antje668
am 28 Mär. 2022
Kommentiert: antje668
am 28 Mär. 2022
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 Kommentare
Akzeptierte Antwort
Scott MacKenzie
am 28 Mär. 2022
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.
Weitere Antworten (1)
Davide Masiello
am 28 Mär. 2022
Bearbeitet: Davide Masiello
am 28 Mär. 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!