Syntax
replacemat(A,valold,valnew)
Input Parameter
A : | | vectors or matrices |
valold : | | existing values |
valnew : | | new values |
Examples
A=[1 2 3; 4 5 6], replacemat(A,1,9)
A=[1 2 3; 4 5 6], replacemat(A,[1 9],[9 0])
Copyright 2017-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 a MATLAB function named replacemat
that replaces specific values in a vector or matrix with new values. It is part of the SG-Library and was created by Tim Lueth in 2017.
Input Parameters
- A: This is the input matrix or vector where the replacement will occur.
- valold: A vector containing the values in
A
that need to be replaced.
- valnew: A vector containing the new values that will replace the corresponding values in
valold
.
Algorithm Steps
- The function iterates over each element in the
valold
vector using a for-loop.
- For each element
valold(i)
, it finds all occurrences of this value in the matrix or vector A
.
- It replaces each occurrence of
valold(i)
in A
with the corresponding value valnew(i)
.
Example Usage
Consider a matrix A = [1 2 3; 4 5 6]
:
- Using
replacemat(A, 1, 9)
will replace all occurrences of 1
in A
with 9
.
- Using
replacemat(A, [1 9], [9 0])
will replace 1
with 9
and 9
with 0
in A
.
Algorithm explaination created using ChatGPT on 2025-08-18 22:01. (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