Finding minimum output value for same inputs in a table
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
antje668
el 28 de Mzo. de 2022
Comentada: antje668
el 28 de Mzo. de 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 comentarios
Respuesta aceptada
Scott MacKenzie
el 28 de Mzo. de 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.
Más respuestas (1)
Davide Masiello
el 28 de Mzo. de 2022
Editada: Davide Masiello
el 28 de Mzo. de 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 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!