Ignore zero values when searching for minimum value in column of matrix
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Robert Demyanovich
el 12 de Nov. de 2021
Respondida: Jon
el 12 de Nov. de 2021
I have the following code to find the minimum value in the last column of matrix cANALY:
[tnValueAnaly, tnRowAnaly] = min(cANALY(:,1));
My simulation, however, has 100,000 time steps and takes quite awhile to run. The code above works if I allow the simulation to run the entire 100,000 time steps. However, the answer that I need generally can be found well before the 100,000 time steps. The simulation has a chart that updates so I know about when the values for tnValueAnaly, tnRowAnaly are available for extraction from the table. However, it is probably easiest to get these values once the entire table is filled in. The problem is that if the entire table isn't filled in (i.e. I manually ended the simulation early), then the lowest value in the last column of cANALY is zero which occurs when I ended the simulation.
So, how, can I modify the code above to ignore values of zero when determining the minimum? When the matrix is first created, prior to the start of the simulation, it is populated with values of zero.
0 comentarios
Respuesta aceptada
Jon
el 12 de Nov. de 2021
idl = cANALY(:,1)>0 % use logical indexing
[tnValueAnaly, tnRowAnaly] = min(cANALY(idl,1));
0 comentarios
Más respuestas (0)
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!