image thumbnail
from 2D random paths generator integrating leg's contraints by Sebastien PARIS
Generates random 2D leg'paths from departure to arrival integrating leg's constraints

mat_dist.m
function C = mat_dist(V , I , val);

%  Return the Euclidian matrix given nodes coordinate matrix and adjacency
%  matrix I
%
% Usage
% -----
%
% C = mat_dist(XY , I , [val]);
%
%
% Inputs 
% ------
%
%
% XY        Nodes coordinates (2 x S)
% I         Adjacency matrix  (D x S)
% val       Raplace values  (default Inf)
%
%
% Output 
% ------
%
% C         Euclidian matrix (D x S)
%
% Author          Sbastien PARIS (sebastien.paris@lsis.org)
% -------


if (nargin < 3)
   
   val = + Inf;
   
end


[D S] = size(I);

C     = val(ones(D , 1) , ones(1 , S));

II    = find(I);

Iy    = floor( (II - 1)/D ) + 1;

temp  = ( V(: ,  I(II)) - V(: , Iy) );

d     = sqrt(sum( temp.*temp , 1) );

maxd  = max(d);

C(II) = d./maxd;

%C(II) = d;

Contact us at files@mathworks.com