please explain function [dum,z]

8 次查看(过去 30 天)
Kalai
Kalai 2014-9-30
[dum,z] = min([sq_dist1;sq_dist2],[],1);

回答(1 个)

Michael Haderlein
Michael Haderlein 2014-9-30
from the Matlab help:
C = min(A,[],dim)
[C,I] = min(...)
So, [sq_dist1;sq_dst2] is an array (most likely 2-dimensional) whose minimum will be searched.
[] is required as otherwise the array will be compared with the value of this parameter:
min(3,2) -> 2
1 is the dimension along which the minimum values are searched. To understand, just check the difference between
min(magic(3),[],1)
and
min(magic(3),[],2)
That should make it clear.
[dum,z] are the values which are returned. In this case, I suppose dum stands for dummy which means you are actually not interested in this variable, but you need it to get the second parameter. Note that in later releases, you can also use [~,z] which is little more memory efficient. z indicates the indices at which the minimum values are found.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by