MATLAB: H5L.iterate exception and behavior of native matlab functions() method

functionsh5lh5l.iteratehdf5

Hello,
I'm developing a wrapper to use hdf5 files via set of low-level [+H5(?)] packages, provided my Matlab. As a part of this project I need to use H5L.iterate method, that has the following signature:
[status idx_out opdata_out] = H5L.iterate(group_id,index_type,order,idx_in,iter_func,opdata_in)
where iter_func is a pointer to a callback function that is supposed to be used on every step of iteration.
The H5L.iterate method is called inside a general class (let's say hdf5Adapter), so I would like to use a handle to another method of hdf5Adapter as [iter_func] argument for H5L.iterate.
However when doing so I receive an exception thrown by H5L.iterate caused by the following validation inside H5L.iterate (%matlabroot\toolbox\matlab\imagesci\+H5L\iterate.m) :
f = functions(iter_func);
if isempty(f.file)
error(message('MATLAB:imagesci:H5:badIterateFunction'));
end
because f.file appears to be empty.
I have tested the behavior of functions() method when applied to class methods (example below) and it seems to return empty 'file' field in the return data structure. See the test class definition in the attachment.
The way I test it:
foo = tstClass();
disp('instance method, as object');
ifhi = @foo.testFuncInstance; % instance method, as object
disp(functions(ifhi));
disp('instance method, as class');
cfhi = @tstClass.testFuncInstance; % instance method, as class
disp(functions(cfhi));
disp('static method, as object');
ifhs = @foo.testFuncInstance; % static method, as object
disp(functions(ifhs));
disp('static method, as class');
cfhs = @tstClass.testFuncInstance; % static method, as class
disp(functions(cfhs));
My questions are the following:
  1. Is there any way to make the result struc of functions(handle_to_class_method) to have a non-trivial 'file' value?
  2. What is the purpose of the check 'if isempty(f.file)' in H5L.iterate?
Thank you, Maxim Semyonov

Best Answer

I do not know why H5L.iterate needs function handles with a file defined. I suggest you file an enhancement request to remove the requirement.
I can give you a workaround. You will need to make two changes.
  1. Create your function handles from a function not a script.
  2. The instance method as class and static method as class function handles must be created in the form of an anonymous function:
cfhi = @() tstClass.testFuncInstance; % instance method, as class
cfhs = @() tstClass.testFuncStatic; % static method, as class
If you look at the function line the parser is doing this for you but because it is generating the code the file is not being filled in. In the case of a script the owning file is the calling function or the base workspace.
Just a note here you can't call an instance method in the form classname.method not sure why you are testing that. My recomended syntax for a call to an instance method for iterating would be:
fh=@(loc_id,attr_name) myIterateMethod(obj, loc_id, attr_name);