필터 지우기
필터 지우기

Function handle invoking Java reports syntax error?

조회 수: 2 (최근 30일)
Ahmed Fasih
Ahmed Fasih 2012년 3월 6일
Why does
d='.'; mylength = length(java.io.File(d).listFiles(org.apache.commons.io.filefilter.WildcardFileFilter('*.dat')))
work, but a function handle for input "d" fail with a syntax error?
length_func = @(d) length(java.io.File(d).listFiles(org.apache.commons.io.filefilter.WildcardFileFilter('*.dat')))
??? Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
  댓글 수: 1
Ahmed Fasih
Ahmed Fasih 2012년 3월 7일
This following does work:
helper=@(f) f.listFiles(org.apache.commons.io.filefilter.WildcardFileFilter('*.dat'))
length_func = @(d) length(helper(java.io.File(d)))

댓글을 달려면 로그인하십시오.

답변 (1개)

Laurens Bakker
Laurens Bakker 2012년 3월 7일
Hi Ahmed,
anonymous functions are not allowed to store any data, and accessing a field of java.io.File(d) probably implicitly does this.
Cheers,
Laurens

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by