MATLAB: How to create an array of file pointers for code generation in MATLAB 7.14 (R2012a) using MATLAB Coder 2.2

matlab coder

I have read in the documentation that one can create a file pointer using:
fp = coder.opaque('FILE *', 'NULL')
and that CODER.OPAQUE does not support the creation of arrays, but I would like to create an array of file pointers so that I can index the variable, i.e. fp(1).

Best Answer

The below information is available for R2012b at the following link:
Creating an array of file pointers directly with CODER.OPAQUE is not currently supported in MATLAB 7.14 (R2012a) using MATLAB Coder 2.2.
As a workaround you can create an array of file pointers by combining the CODER.OPAQUE and REPMAT commands as follows:
fp = repmat(coder.opaque('FILE *', 'NULL'),1,size);
Where size is the number of file pointers you wish to create in the array. The variable fp is not dynamically expandable, however it can be indexed with standard MATLAB syntax, i.e. fp(1) is the first file pointer, etc.