How to get file names in a folder, when using C/C++ Code Generation

8 次查看(过去 30 天)
Hi! My code needs to get all bmp image file names in a folder , and convert it to C++ dll by Matlab Coder. Unfortunately, Matlab Coder is not support the dir function . I want to find a replacement method to get all bmp file names in a folder and also can be used in Matlab Coder.
Thanks a lot!

回答(1 个)

Jinal
Jinal 2023-10-18
编辑:Jinal 2023-10-20
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)
coder.extrinsic("dir");
coder.extrinsic("cd");
cd(folderpath);
fn = dir('**/*.bmp');
end
  • Generate MEX code for “bmplist” by typing the following command.
codegen bmplist -args {"hi"}
  • Call the generated MEX code.
bmplist(folderpath);
%folderpath is the path to the folder in which BMP files are to be searched for
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.

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by