Hello Guan,
As per my understanding, you want to generate C/C++ code from your MATLAB code that lists the names of all BMP files present in a folder.
At present, functions such as “dir” and “ls” are not supported by MATLAB Coder for C/C++ code generation.
Any of the following workarounds can be used to include functions not supported by MATLAB Coder:
1) Use “coder.extrinsic” to call the unsupported functions. “coder.extrinsic” declares function as an extrinsic function. The code generator uses the MATLAB® engine to execute the call.
Please find below a sample workflow to list BMP files present in a folder:
- Create a local function called “bmplist” as follows.
Create a local function called “bmplist” as follows.
function fn = bmplist(folderpath)
- Generate MEX code for “bmplist” by typing the following command.
codegen bmplist -args {"hi"}
- Call the generated MEX code.
To know more about “coder.extrinsic”, please refer this link:
2) Write custom code for the unsupported functions.
3) Use “coder.ceval” to call custom C functions that replace the unsupported functions.
To know more about “coder.ceval”, please refer the following link:
Please refer the following link to know more about workarounds for using functions not supported for Code Generation:
I hope this resolves the issue you were facing.