matrixfilldistance

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 4.8, Creation date: 2019-12-11, Last change: 2025-09-14

fills a potential field



See Also: GPLofmatrix , matrixdistanceofCPL , ELofmatrixneigbors , ELofmatrixneigborweight , matrixlocalminmax , matrixskeleton

Example Illustration

 missing image of matrixfilldistance(M,lst);

Syntax

MM=matrixfilldistance(M,lst);

Input Parameter

M: Matrix
lst: start point list

Output Parameter

MM: Distancematrix

Examples


m=100; M=circshift(reshape(1:m*m,m,[]),[floor(randminv(m)),floor(randminv(m))])
n=m; for i=1:n; M(floor(randminv(m)),floor(randminv(m)))=nan; end; M
matrixfilldistance(M,[ceil(rand*m*m), ceil(rand*m*m)])




Copyright 2019-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This algorithm is designed to fill a potential field in a matrix by calculating the distance from specified start points. It is part of the SolidGeometry library and was introduced in version 4.8.

Input Parameters

Output Results

Algorithm Steps

  1. Initialize the distance matrix MM as a copy of M.
  2. Set all non-NaN elements of MM to infinity to indicate unvisited points.
  3. Set the distance of the start points in lst to zero in MM.
  4. Initialize a counter k to zero, which will represent the distance level.
  5. Enter a loop that continues until there are no more points to process in lst:
  6. Once the loop exits, check if there are no output arguments. If so, plot the distance matrix MM using matrixplot and display a color bar.

Example Usage

The example provided in the code demonstrates how to create a random matrix M, introduce NaN values, and then calculate the distance matrix from random start points.

Algorithm explaination created using ChatGPT on 2025-08-19 00:55. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21