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

6 次查看(过去 30 天)
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.

采纳的回答

Jon
Jon 2021-11-12
idl = cANALY(:,1)>0 % use logical indexing
[tnValueAnaly, tnRowAnaly] = min(cANALY(idl,1));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dictionaries 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by