Filter löschen
Filter löschen

Find minimum distance columnwise

1 Ansicht (letzte 30 Tage)
Manuel Schmidberger
Manuel Schmidberger am 4 Apr. 2019
Hi,
I have two matrices TRX and TRY [M x N] with cartesian coordinates. The coordinates are coordinates of an object which is moving by time (increasing N = timesteps) and is able to split or merge (M). I wanna calculate the shortest track through this points in direction N (from timestep to timestep). But notice, I wanna find the minimum track which means the points are depending on each other columnwise.
Example
TRX=[1 10 15 20; NaN 5 10 NaN; NaN NaN 12 NaN];
TRY=[5 15 20 25; NaN 7 19 NaN; NaN NaN 23 NaN];
I'm searching for the shortest distance from TRX(1,1) to TRX(1,end) and (TRY ofc). It should be taken into account that the shortest way between timestep 1 (first column) and timestep 2 (second column) is from TRX(1,1) to TRX(2,2) (and TRY). Thus the next way can only start from TRX(2,2)|TRY(2,2) and not be e.g. from TRX(1,2)Y(1,2) to TRX(:,3)TRY(:,3)
Is there any option to get this with a fast code? It is a kind of "find minimum over all distance by taking partial distances and connected neighbors into account"? I first tried nchoosk to get the hole bunch of variations but that won't work if the matrix increases in M and/or N direction due to to many possible combinations.
Now I calculate distances with
for i=1:size(TRX,2)-1
Xts_1=TRX(:,i+1);
Xts_0=TRX(:,i);
diffX(:,1)=reshape(bsxfun(@minus, permute(Xts_0,[1,3,2]), permute(Xts_1,[3,1,2])),[],1);
Yts_1=TRY(:,i+1);
Yts_0=TRY(:,i);
diffY(:,1)=reshape(bsxfun(@minus, permute(Yts_0,[1,3,2]), permute(Yts_1,[3,1,2])),[],1);
trackdist=sqrt(diffX.^2+diffY.^2);
dist(1:length(find(~isnan(trackdist)==1)),i)=trackdist(~isnan(trackdist));
clear Xts_1 Xts_0 diffX diffY Yts_1 Yts_0
end
Now I got the distances dist between each points at any connected time steps (N), but from now I struggle how to finde the best track on mentioned conditions.
At the end I wanna return the TRX and TRY coordinates for a "best track" including the indices for this coordinates.
Looking forward for any help, hints or tricks!
Thank and best regards
Manuel

Antworten (0)

Produkte


Version

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by