How to find the index of the minimum value in a matrix.
388 ビュー (過去 30 日間)
So I have a 9x21 matrix, V, and I am trying to find the index (i,j) of the minimum (closest to zero) value in that matrix. I have tried using several forms of the min function, but it keeps returning multiple indices for the the minimum values in each column. I only want one index (i,j), that of the minimum value in the ENTIRE matrix.
How would I go about doing this? Thanks!
回答 (3 件)
Yusuf Suer Erdem 2022 年 1 月 19 日
Hi, did you try it with this way. It gives the index which has the smallest number.
a=[8 2 5 1;2 -2 4 0;9 5 4 8];
Steven Lord 2022 年 1 月 20 日
Since you're using release R2021b (according to the information listed on the right side of this page) you can use 'all' as the dimension input and specify both the ComparisonMethod parameter and the 'linear' option.
M = randn(6)
[minValue, minIndex] = min(M, , 'all', 'linear', 'ComparisonMethod', 'abs')
For this particular random matrix, the entry with the smallest absolute value is the element with linear index 30.