Julia Function Handle

138 Views Asked by At

I want to perform a function_handle in Julia as MATLAB does. Suppose I create a function in MATLAB like this:

fn = @(b, x) process(b, x, @trans);

And then I put this function as input of another function function m = AnotherFunc(m, l, func) where m is a matrix by:

m = AnotherFunc(m, l, fn);

And in this AnotherFunc, I should use the function I created as

m(a:b,c) = func(m(a:b,c), d);

How can I perform this via Julia?

For these 3 I wrote these in Julia:

fn = (b,x) -> process(b, x, trans);

m = AnotherFunc(m, l, fn);

m[a:b,c] = func(m[a:b,c], d);

Then shows ArgumentError: invalid index: 3.0 of type Float64

I want to write something can perform the same as in MATLAB.

1

There are 1 best solutions below

0
jerlich On
fn(b,x) = process(b,x,trans);
AnotherFun(m,l,fn) = begin
  m[a:b,c] = fn(m[a:b,c], d);
  return m
end

Note: you did not provide a minimal working example. The variable l seems unused and it is not clear where the variables trans, a,b,c,d are set.