I am trying to build a fileDatastore from multiple large files using a custom read function. This should work like
fds = fileDatastore(location, 'ReadFcn', @fcn)
I use a cell array containing several fullfile strings for location, which should be fine. I simply can't figure out how to handle the read function which has multiple input and output variables and looks like this:
[A, B, C] = function(filestring, x, y, z)
How can I make this work? Thanks in advance!
You can use an " anonymous function " to do part of this. An anonymous function lets you adapt the prototype of the function, "binding" in values, so one piece of the puzzle is to do this:
x = 7; y = 42; z = -1;
fcn = @(filename) myfunction(filename, x, y, z);
This makes a function fcn
which you can call like fcn('somefile')
and the effect is myfunction('somefile', 7, 42, -1)
.
Unfortunately, there's a twist - fileDatastore
needs a function returning only a single output. This is not something you can fix with an anonymous function, so you'll need to write a function in a MATLAB code file that does something like this perhaps:
function out = wrapMyFunction(filename, x, y, z)
[A,B,C] = myfunction(filename, x, y, z);
out = {A,B,C};
end
And then use
fcn = @(filename) wrapMyFunction(filename, x, y, z);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.