2016-07-21 4 views
0

Matlab! 나는이 오픈 소스 코드를 가지고 내가 원하는 것을 할 수 있도록 해왔다.하지만 그렇게하고 싶지는 않지만 그렇게하고 싶다. 이걸 감싸는 데 도움이 필요해.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

여기 [link] (http://stackoverflow.com/questions/32379805/linear-indexing-logical-indexing-and-all-that) 및 여기 [link] (http : //www.mathworks .com/company/newsletters/articles/matrix-indexing-in-matlab.html). – Rotem

답변

0

MATALB에서 명령문 끝에 세미콜론을 넣지 않으면 해당 명령문의 출력이 콘솔에 인쇄됩니다. 따라서 다음 진술 :

[source_id, distances] = geodesic_distance_and_source(algorithm) 

에는 세미콜론이 없습니다. 나는 그것이 당신이 12000의 거리를 인쇄하는 것을 보는 곳이라고 생각한다.

두 번째 질문에 대답하려면 : distances 행렬의 구조에 대한 정보가 충분하지 않습니다. 색인 생성을 사용하여 소스 m과 대상 n 사이의 거리를 distances(m,n)으로 알 수 있습니다. 그것이 일반적으로 거리 매트릭스가 구조화되는 방법입니다.하지만 확실히 말할 수는 없습니다.

관련 문제