0

I am currently using this code:

assert(isa(values,'double'));
assert(size(values, 1) <= 1000);

to persuade matlab coder to make values a one dimensional array. The end aim is to be able to interface with it via C# and PInvoke. This creates a C signature containing this:

const real_T values[1000], const int32_T values_size[1]

I seem to be able to use this even for one dimensional arrays where the lengths is less than 1000. Are there neater ways to achieve the above (i.e. assert that values is a one dimensional array of unlimited length)?

PS:

I have also used:

assert(all(size(values) == [1 Inf]));

but shelved this for now as the created struct seems to be very complicated (see also here) and I do not know how to populate it from C#.

Community
  • 1
  • 1
cs0815
  • 16,751
  • 45
  • 136
  • 299
  • Sorry, I deleted the other one. – cs0815 Feb 18 '13 at 13:10
  • One reason: MEX-functions call into MATLAB run-time libraries, so you do need to have MATLAB ... – cs0815 Feb 18 '13 at 13:41
  • To get this right: Your application is in C#. You have Matlab source that you want to translate Matlab -> C. The resulting C should be callable by C#. – edgar.holleis Feb 18 '13 at 18:00
  • Yes - sorry if I was unclear. I would prefer 'my' assert method ... – cs0815 Feb 18 '13 at 18:30
  • By the way, I now know how to fill out `struct_emxArray_real_T`. It's explained here: http://www.mathworks.co.uk/help/fixedpoint/ug/c-code-interface-for-unbounded-arrays-and-structure-fields.html If you undeleted your other question I think I could answer now. The thing that confused me all along was you talking about matlab coder. I thought that was a person, a colleague of yours! – David Heffernan Feb 18 '13 at 21:21
  • Thanks david - sorry for not being clear enough. Thought everyone knows THE matlab coder (-: Will undelete question tomorrow. – cs0815 Feb 18 '13 at 21:49
  • Yeah, I'm clearly ignorant! ;-) Will remember that now though. Actually the link I found (independently) is the same one in your answer. – David Heffernan Feb 18 '13 at 22:03
  • Ok thanks. I'll have a look into it – cs0815 Feb 19 '13 at 08:03
  • @David I have re-posted my question here: http://stackoverflow.com/questions/15022890/emxarray-real-t-to-c-sharp-struct-plus-initialisation – cs0815 Feb 22 '13 at 12:35

1 Answers1

1

Matlab coder now seems to support dynamic memory allocation (that wasn't the case when I last used it around 2008).

A full example: http://www.mathworks.de/products/matlab-coder/examples.html?file=/products/demos/shipping/coder/coderdemo_atoms.html

Update: For dynamically sized arrays Matlab uses EMX data structures: http://www.mathworks.de/de/help/fixedpoint/ug/c-code-interface-for-unbounded-arrays-and-structure-fields.html

edgar.holleis
  • 4,803
  • 2
  • 23
  • 27
  • Thanks. Not sure if this helps. I might be missing something here but I cannot see where they assert (as in my situation!) that the variable to be passed in is a one dimensional array of non-fixed size. Thanks – cs0815 Feb 18 '13 at 15:24
  • 1
    Asserts are not the only way. The alternative is to tell `codegen` on the command line what to assume about arguments of the function it translates. In the example I linked to the command line is: `codegen run_atoms -args {coder.typeof(atom, [1 Inf]),int32(0),int32(0)} -config cfg` – edgar.holleis Feb 18 '13 at 18:02