[英]How to find non zero minimum array in a 2D matrix in matlab
I have a 2D matrix as shown below: 我有一个2D矩阵,如下所示:
A =
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8193 0.6429 0.4731
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8172 0.6395 0.4696
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8099 0.6285 0.4582
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.7938 0.6066 0.4364
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.7588 0.5675 0.4006
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8527 0.6739 0.5039 0.3477
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8825 0.7371 0.5803 0.4264 0.2807
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.7928 0.6327 0.4838 0.3406 0.2054
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 0.8846 0.7945 0.6560 0.5173 0.3816 0.2469 0.1131
1.0000 1.0000 1.0000 1.0000 1.0000 0.8598 0.7438 0.6373 0.5194 0.3988 0.2785 0.1522 0
1.0000 1.0000 1.0000 0.8710 0.7956 0.6954 0.5935 0.4916 0.3856 0.2799 0.1814 0.0834 0
0.7915 0.7845 0.7581 0.6884 0.6159 0.5326 0.4432 0.3500 0.2514 0.1538 0.0838 0 0
0.5972 0.5882 0.5596 0.5085 0.4471 0.3760 0.2967 0.2137 0.1163 0 0 0 0
0.4208 0.4116 0.3836 0.3389 0.2881 0.2274 0.1540 0.0919 0 0 0 0 0
0.2629 0.2536 0.2244 0.1755 0.1388 0.0915 0 0 0 0 0 0 0
0.1235 0.1155 0.0850 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
I want to remove its zero arrays and then find the minimum value of each column and put those minimum values in a vector. 我想删除其零数组,然后找到每列的最小值并将这些最小值放入向量中。
I just used find(A ~= 0)
but it's not working. 我只是使用
find(A ~= 0)
但是它不起作用。
How can I do that? 我怎样才能做到这一点?
Replace all of the zeroes with NaN
, then apply min
to each column independently. 将所有零替换为
NaN
,然后将min
分别应用于每个列。 Setting values to NaN
in a matrix / vector allows min
to ignore those values, so you'd effectively be ignoring the zeroes. 在矩阵/向量中将值设置为
NaN
可使min
忽略这些值,因此您实际上将忽略零。 Assuming that your matrix is in A
, do this: 假设您的矩阵在
A
,请执行以下操作:
Anan = A;
Anan(A == 0) = NaN;
out = min(Anan, [], 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.