Syntax
PLrc=matrixrand(M,[n])
Input Parameter
M : | | Matrix |
n : | | number of random coordianates |
Output Parameter
PLrc : | | coordinate list for matrix M |
Examples
M=zeros(5,10), matrixrand(M,6)
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 function, matrixrand
, generates random coordinates within the dimensions of a given matrix. It is primarily used for testing path planning in a 2D space.
Input Parameters
- M: A matrix or its size. If a matrix is provided, its size is extracted. If the size is provided directly, it is used as is.
- n: The number of random coordinates to generate. This is an optional parameter, defaulting to 1 if not specified.
Output
- PLrc: A list of random coordinates within the matrix dimensions. It is an
n
by 2 matrix, where each row represents a coordinate.
Algorithm Steps
- Check if the input
M
is a matrix with more than one row. If so, issue a warning that the function is faster if only the size is provided.
- Determine the size of the matrix
M
and store it in MS
.
- Retrieve the number of random coordinates
n
using the helper function getfuncparams
. If n
is not provided, default to 1.
- Initialize
PLrc
as a zero matrix with n
rows and 2 columns.
- For each coordinate to be generated (from 1 to
n
):
- Generate a random integer for the row index using
randminv
within the range [1, number of rows in M
].
- Generate a random integer for the column index using
randminv
within the range [1, number of columns in M
].
- Store the generated coordinate in the
PLrc
matrix.
Algorithm explaination created using ChatGPT on 2025-08-18 23:41. (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