0

I want to generate mex function using Matlab coder: MEX function. In my code I used dir function to get the information of the images with png format like below:

%#codegen
coder.inline('never')
coder.extrinsic('dir')
imgePath ='D:/images/';
images = dir([imgePath '*.png']);
I=(mat2gray( imread(([imgPath ,images(1).name]))));

the output of dir function is a structure and its lengths depend on the number of png files in imgePath. When I build the code I encountered the below error:

Subscripting into an mxArray is not supported.

How can I solve this problem?

  • Output of extrinsic functions are mxArray types and generated C code cannot look inside them. Can you move your directory functions outside your code generation and pass the file names as inputs? – Navan Apr 13 '17 at 20:44
  • in this case I think I can, but I have many other matrixes which I need look inside them to compute the other parameters! you mean there is no way for this issue?! – Sahar Sahar Apr 14 '17 at 06:46
  • If the mxarray types and sizes are known, you can pre-initialize the variables with those types before calling the extrinsic function. Then the conversion will happen. When calling dir you cannot know the size of the path which is why you cannot pre-initialize. – Navan Apr 14 '17 at 17:12

0 Answers0