GNU Octave method to operate on each item in a matrix. octave "arrayfun(...)" example

function, linux, octave

Solution

Simpler way, As Nasser Pointed out, the following octave code:

f=@(x) x+5;
A = [1, 0, -1; 3, 4, 5];
result = f(A)
result

applies (x+5) to every element passed in, it prints:

result =
    6    5    4
    8    9   10

Problem

In GNU Octave version 3.4.3, I am having trouble applying a custom function to operate on each item/element in a matrix. I have a (2,3) matrix that looks like: ``` mymatrix = [1,2,3;4,5,6]; mymatrix 1 2 3 4 5 6 ``` I want to use each element of the matrix as an input, and run a custom function against it, and have the output of the function replace the content of mymatrix item by item.

Original source