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
Syntax
MM=matrixfilldistance(M,lst);
Input Parameter
M: | | Matrix |
lst: | | start point list |
Output Parameter
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
- M: A matrix that represents the field to be filled.
- lst: A list of start points within the matrix from which distances will be calculated.
Output Results
- MM: A distance matrix where each element represents the distance from the nearest start point.
Algorithm Steps
- Initialize the distance matrix
MM as a copy of M.
- Set all non-NaN elements of
MM to infinity to indicate unvisited points.
- Set the distance of the start points in
lst to zero in MM.
- Initialize a counter
k to zero, which will represent the distance level.
- Enter a loop that continues until there are no more points to process in
lst:
- Find all neighboring points of the current list of points
lst using the function ELofmatrixneigborweight.
- Filter these neighbors to include only those that have not been visited (i.e., their value in
MM is infinity).
- Update
lst to this new list of neighbors.
- Increment the distance counter
k.
- Set the distance of the new list of neighbors in
MM to k.
- 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