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 Center および File ExchangeDictionaries についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by