Ignore zero values when searching for minimum value in column of matrix

6 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Jon
Jon el 12 de Nov. de 2021
idl = cANALY(:,1)>0 % use logical indexing
[tnValueAnaly, tnRowAnaly] = min(cANALY(idl,1));

Más respuestas (0)

Categorías

Más información sobre Dictionaries en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by