0

New to Matlab! I've been messing around with this open source code to make it do what I want and it does, but not the way I want it to. I just need some help wrapping this up.

This is what I have so far:

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

It prints out distances and then, in subsequent code, it plots the path.

So here's my problem. It prints out 12000+ distances corresponding to each of my "sources" but I only care about distances between 10 sources and 12 destinations on my mesh, given by vertices and faces. How can I get it to print the 120 distances I care about and store them in a matrix?

Amanda
  • 31
  • 8
  • Refer here: [link](http://stackoverflow.com/questions/32379805/linear-indexing-logical-indexing-and-all-that) and here: [link](http://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html). – Rotem Jul 21 '16 at 14:55

1 Answers1

0

In MATALB, if you don't put a semicolon at the end of your statement, then, the output of that statement gets printed on the console. So, your following statement:

[source_id, distances] = geodesic_distance_and_source(algorithm) 

does not have a semicolon. I suspect that's where you see 12000 distances printed out.

To answer your second question: I don't have enough information about the structure of matrix distances. I think you can use indexing to find out distance between source m and destination n as distances(m,n). That's how usually distance matrices are structured, but I can't say for sure.

Autonomous
  • 8,935
  • 1
  • 38
  • 77