Matlab新手!我一直在搞乱这个开源代码,让它做我想做的事情,但不是我想要的方式。我只是需要一些帮助来解决这个问题。
这是我到目前为止所做的:
clear
global geodesic_library;
geodesic_library = 'geodesic_debug'; %"release" is faster and "debug" does additional checks
rand('state', 0); %comment this statement if you want to produce random mesh every time
load V3_Elements4GeodesicD.k
load V3_Nodes4GeodesicD.k
vertices = V3_Nodes4GeodesicD (:, [2 3 4]);
faces = V3_Elements4GeodesicD (:, [3 4 5]);
N = 12240; %number of points in a mesh
mesh = geodesic_new_mesh(vertices,faces); %initilize new mesh
algorithm = geodesic_new_algorithm(mesh, 'exact'); %initialize new geodesic algorithm
vertex_id = 6707 ; %create a single source at vertex #1
source_points = {geodesic_create_surface_point('vertex',vertex_id,vertices(vertex_id,:))};
geodesic_propagate(algorithm, source_points); %propagation stage of the algorithm (the most time-consuming)
vertex_id = 12240; %create a single destination at vertex #N
destination = geodesic_create_surface_point('vertex',vertex_id,vertices(vertex_id,:));
path = geodesic_trace_back(algorithm, destination); %find a shortest path from source to destination
distances = zeros(N,1); %find distances to all vertices of the mesh (actual pathes are not computed)
[source_id, distances] = geodesic_distance_and_source(algorithm) %find distances to all vertices of the mesh; in this example we have a single source, so source_id is always equal to 1
geodesic_delete; %delete all meshes and algorithms
打印出距离,然后在后续代码中绘制路径。
所以这是我的问题。它打印出对应于我的每个“源”的12000+个距离,但我只关心我的网格上10个源和12个目的地之间的距离,由顶点和面给出。如何才能打印我关心的120个距离并将它们存储在矩阵中?
答案 0 :(得分:0)
在MATALB中,如果未在语句末尾添加分号,则该语句的输出将打印在控制台上。那么,您的以下声明:
[source_id, distances] = geodesic_distance_and_source(algorithm)
没有分号。我怀疑你打算看到12000个距离。
回答第二个问题:我没有足够的关于矩阵distances
结构的信息。我认为您可以使用索引来查找源m
和目标n
之间的距离distances(m,n)
。这通常是距离矩阵的结构,但我不能肯定地说。