朱莉娅 - 如何获得每行矩阵的最小值?

Tag*_*med -1 for-loop multidimensional-array julia

我试图制作该代码,但它获得了行中最后一个索引的值

function heuristicCalculate(distanceBetweenCities,numOfCities) 
#distanceBetweenCities is a 29*29 array 
#Use this function to calculate the tour length using nearest neighbor heuristic Lnn
mindist=zeros(29,1)
  for i=1:29
    for j=1:29
    mindist[i,1]=Base.minimum(distanceBetweenCities[i,j])
    end
  end
  mindist
  return Lnn, tau0
  #Lnn  tour length using nearest neighbor heuristic
  #tau0  a value representing the initial phermone amount =1/(n*Lnn)
end
Run Code Online (Sandbox Code Playgroud)

meg*_*art 5

最简单的解决方案可能是

mindist = minimum(distanceBetweenCities,2)
Run Code Online (Sandbox Code Playgroud)

其中,,2表示搜索最小值的维度.