This paper is connected with the shortest path problem.A matrix method is proposed to solve the problem using Dijkstra algorithm,which can directly get the distance and the path from the source node to other nodes with simple calculation and label in weight matrix.The method can be easily completed on computer.