matrixvalues

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

returns the values of a matrix from a list of coordinate entries

Description

most probably there is a faster an simpler method in matlab

See Also: GPLofmatrix , matrixneighbors , matrixdistancefield

Example Illustration

 missing image of matrixvalues(M,el)

Syntax

Res=matrixvalues(M,el)

Input Parameter

M: Matrix
el: list of [r c] coordinates

Output Parameter

Res: Result

Examples


m=5; M=circshift(reshape(1:m*m,m,[]),[floor(randminv(m)),floor(randminv(m))])
matrixvalues(M,[1 1; 2 2; 3 3;1 4])




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, matrixvalues, retrieves values from a matrix M based on a list of coordinate entries provided in el.

Input Parameters

Output

Algorithm Steps

  1. Determine the number of coordinate pairs in el using size(el,1) and store it in n.
  2. Initialize the result vector Res with NaN values of size n by 1.
  3. Create an index vector il ranging from 1 to n.
  4. Identify rows in el where the first column is NaN using isnan(el(il,1)) and store the result in nl.
  5. Filter out indices where the first column of el is NaN by updating il to il(~nl).
  6. Iterate over the filtered indices il:

Example

Consider a matrix M created by reshaping and circularly shifting a sequence of numbers. The function matrixvalues(M,[1 1; 2 2; 3 3; 1 4]) will return the values from M at the specified coordinates.

Algorithm explaination created using ChatGPT on 2025-08-18 23:22. (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