Syntax
Res=matrixvalues(M,el)
Input Parameter
M : | | Matrix |
el : | | list of [r c] coordinates |
Output Parameter
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
- M: A matrix from which values are to be extracted.
- el: A list of coordinates in the form of a two-column matrix, where each row represents a coordinate pair [r, c].
Output
- Res: A column vector containing the values from matrix
M
at the specified coordinates in el
.
Algorithm Steps
- Determine the number of coordinate pairs in
el
using size(el,1)
and store it in n
.
- Initialize the result vector
Res
with NaN
values of size n
by 1.
- Create an index vector
il
ranging from 1 to n
.
- Identify rows in
el
where the first column is NaN
using isnan(el(il,1))
and store the result in nl
.
- Filter out indices where the first column of
el
is NaN
by updating il
to il(~nl)
.
- Iterate over the filtered indices
il
:
- For each index
i
, retrieve the value from matrix M
at the row and column specified by el(i,1)
and el(i,2)
, respectively.
- Assign this value to
Res(i)
.
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