Search code examples
matlabmatlab-cvstcode-generation

use argument to system object in matlab code generation


I'm tring to use system object for my generated matlab code (.mex)

here is the function.

function [  ] = filereaderTest( videofile )

fileReader = vision.VideoFileReader(videofile);

while ~isDone(fileReader)
    step(fileReader);
    % do something
end

release(fileReader);

end

when I try codegen filereaderTest -args videofile , error occurs. It says "fail to compute constant value for constructor arguement #1. To generate code, all argument for System Object constructor should be constant. ..."

To use VideoFileReader, must pass file name to its constructor. So, here is my question: there is any way to use this function to any files? for example:

filereaderTest.mex(video1);
filereaderTest.mex(video2); % video1 and video2 are different

Solution

  • What you are trying to do is not possible. The documentation states clearly:

    Set arguments to System object™ constructors as compile-time constants. (1)