3

I have written a matlab function to calculate entropy of image "ent=entropoy(image)" and convert it to c++ function by matlab coder.

I do some calculation at ent in c++ file then try to convert all c++ code to matlab function.

I received the

error: 'cannot convert 'uint8* {aka unsigned int*}' to 'const emxArray_uint8_T*'

in entropy function

How declare image 'which input from matlab' in mex function and use it correctly in entropy function?

Rajesh Pandya
  • 1,540
  • 4
  • 18
  • 31
samar
  • 43
  • 5
  • How is `emxArray_uint8_T` defined? Quite likely that `uint8**` is required. – Jodocus May 04 '18 at 11:22
  • 2
    And why does the compiler believe that `uint8` is `unsigned int`? – Bo Persson May 04 '18 at 11:53
  • I did suspect sarcasm, however its completely *[...] obsolete, chatty, or otherwise unnecessary*, so I assumed best intentions – Ander Biguri May 04 '18 at 12:36
  • @Ander As a matter of fact, it is not. I genuinely suspect that funky compiler to have defined `uint8` as a 64bits integer. I've just said it in a mocking manner (seriously, who would _dare_!?). – YSC May 04 '18 at 13:08

1 Answers1

1

To create an emxArray_uint8_T you'll need to use some of the helper functions that Coder generates for you like emxCreate_uint8_T.

The generated emxArray_*_T types from MATLAB Coder are structs used to store dynamically allocated data in the generated code. They contain a data pointer, size vector, and other metadata to manage dynamic allocation.

In MATLAB R2015a and newer, look for the files main.c and main.h in the generated code under the examples directory. Those will give you an example C or C++ main function that show you how to properly construct inputs and invoke the generated code.

The answer:

https://stackoverflow.com/a/24271438/3297440

also covers using the generated emxArray types in more detail and gives links to the MATLAB Coder documentation.

Ryan Livingston
  • 1,898
  • 12
  • 18