1

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.

sssss
  • 21
  • 2
  • 1
    The issue is probably with some variable of a b c d being a floating point number instead of integer. The function declaration seems correct. – fcdimitr Jul 19 '22 at 23:02
  • 6
    Please post a [mre] of your Julia code, and copy-paste the full error message. The error is likely in a different place than you think. – Cris Luengo Jul 20 '22 at 00:08

1 Answers1

0
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.

jerlich
  • 340
  • 3
  • 12