MATLAB Answers

Function handle invoking Java reports syntax error?

6 views (last 30 days)
Ahmed Fasih
Ahmed Fasih on 6 Mar 2012
Why does
d='.'; mylength = length('*.dat')))
work, but a function handle for input "d" fail with a syntax error?
length_func = @(d) length('*.dat')))
??? Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.

  1 Comment

Ahmed Fasih
Ahmed Fasih on 7 Mar 2012
This following does work:
helper=@(f) f.listFiles('*.dat'))
length_func = @(d) length(helper(

Sign in to comment.

Answers (1)

Laurens Bakker
Laurens Bakker on 7 Mar 2012
Hi Ahmed,
anonymous functions are not allowed to store any data, and accessing a field of probably implicitly does this.


Sign in to comment.

Translated by