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

조회 수: 6 (최근 30일)
Robert Demyanovich
Robert Demyanovich 2021년 11월 12일
답변: Jon 2021년 11월 12일
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