matlab-coder

How to convert float[][] type array to “emxArray_real_T *x”

倖福魔咒の 提交于 2019-12-06 06:14:25
I have converted a function which takes a NxN matrix as input and gives a NxN matrix output from matlab to C, using the MatlabCoder. It gave me the function which has two parameters namely void func(const emxArray_real_T *x, emxArray_real_T *y) I get that x is the input to the function and i can get the output of the function from y. The problem is i have a array in float[][] and i wish to give this data as an input to the func, which only takes emxArray_real_T *x as an input. Any ideas on how to convert this float[][] data to emxArray_real_T *x emxArray_real_T has this structure struct

When does Matlab choose to thread when using codegen and parfor

做~自己de王妃 提交于 2019-12-04 19:24:17
I seem to be one of few people using the Matlab coder (codegen command) to get speedup, judging by the fact that there is so little discussion or help on-line. I've gotten incredible speedups from it in some cases. I've never seen it documented, but when I make a MEX file using codegen from a Matlab script with a parfor loop, it often will thread the resulting MEX. Parfor in functions spawns multiple processes which is often less efficient than just threading (I'm inferring all this from watching top in linux and seeing multiple 100% processes in Matlab functions, but a single e.g. 1000%

emxArray_real_T to C# struct plus initialisation

泄露秘密 提交于 2019-12-02 15:21:39
问题 I am trying to create a 'constructor' for this C# struct (initial attempt included): [StructLayout(LayoutKind.Sequential)] public struct emxArray_real_T { public IntPtr data; public IntPtr size; public int allocatedSize; public int numDimensions; [MarshalAs(UnmanagedType.U1)] public bool canFreeData; public emxArray_real_T(double[] cSharpData) { var arraySize = Marshal.SizeOf(cSharpData[0]) * cSharpData.Length; this.data = Marshal.AllocHGlobal(arraySize); // ???? numDimensions = 1;

emxArray_real_T to C# struct plus initialisation

只谈情不闲聊 提交于 2019-12-02 08:25:52
I am trying to create a 'constructor' for this C# struct (initial attempt included): [StructLayout(LayoutKind.Sequential)] public struct emxArray_real_T { public IntPtr data; public IntPtr size; public int allocatedSize; public int numDimensions; [MarshalAs(UnmanagedType.U1)] public bool canFreeData; public emxArray_real_T(double[] cSharpData) { var arraySize = Marshal.SizeOf(cSharpData[0]) * cSharpData.Length; this.data = Marshal.AllocHGlobal(arraySize); // ???? numDimensions = 1; canFreeData = false; } } The C corresponding C struct looks like this: typedef struct emxArray_real_T { real_T

Adjacent and non-adjacent superpixels for an superpixel in an image

六眼飞鱼酱① 提交于 2019-12-01 16:54:30
After segmenting an image into N superpixels, I need to specify the superpixels that are adjacent or non-adjacent to one superpixel and determine this relationship for all superpixels. [L,NumLabels] = superpixels(A,200); How can I specify the adjacent superpixels for each of superpixels ? Update I have tried the solution @Cris Luengo introduced. However the following errors arised : B=imread('H.jpg'); [L,N] = superpixels(B,200); glcms=graycomatrix(L); k=glcms(:,50); %SupNum=50 [r,~]=find(k>0); aa=find(r==50); r(aa)=[]; Update 2 I followed the instruction in MATLAB help but it doesn't work for

Adjacent and non-adjacent superpixels for an superpixel in an image

回眸只為那壹抹淺笑 提交于 2019-12-01 15:54:24
问题 After segmenting an image into N superpixels, I need to specify the superpixels that are adjacent or non-adjacent to one superpixel and determine this relationship for all superpixels. [L,NumLabels] = superpixels(A,200); How can I specify the adjacent superpixels for each of superpixels ? Update I have tried the solution @Cris Luengo introduced. However the following errors arised : B=imread('H.jpg'); [L,N] = superpixels(B,200); glcms=graycomatrix(L); k=glcms(:,50); %SupNum=50 [r,~]=find(k>0)

adapt wrapper class for two dimensional case

你离开我真会死。 提交于 2019-12-01 09:23:16
This question is an extension of this question . I would like to adapt the wrapper for the two dimensional case. This is my first attempt: public class EmxArrayRealTWrapper : IDisposable { private readonly emxArray_real_T _value; private GCHandle _dataHandle; private GCHandle _sizeHandle; public emxArray_real_T Value { get { return _value; } } public EmxArrayRealTWrapper(double[,] data) { _dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned); _value.data = _dataHandle.AddrOfPinnedObject(); _sizeHandle = GCHandle.Alloc(new int[] { data.GetLength(0), data.GetLength(1) }, GCHandleType.Pinned);

adapt wrapper class for two dimensional case

不羁岁月 提交于 2019-12-01 06:56:20
问题 This question is an extension of this question. I would like to adapt the wrapper for the two dimensional case. This is my first attempt: public class EmxArrayRealTWrapper : IDisposable { private readonly emxArray_real_T _value; private GCHandle _dataHandle; private GCHandle _sizeHandle; public emxArray_real_T Value { get { return _value; } } public EmxArrayRealTWrapper(double[,] data) { _dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned); _value.data = _dataHandle.AddrOfPinnedObject();

MATLAB Compiler vs MATLAB Coder

£可爱£侵袭症+ 提交于 2019-11-27 06:40:17
What's the difference between the two? As far as I understand it, MATLAB Compiler wraps the MATLAB code into a .exe file so that it can be used without installing MATLAB, and only requires the MCR. On top of it MATLAB Builder NE can also be used to produce .Net assemblies to be used with .Net framework instead of the .exe file, but they still require MCR. Now I don't understand what MATLAB Coder used for? It generates C/C++ code. But is the MATLAB code really converted into C/C++, or is it merely packaged like in the case of MATLAB Compiler? Does it also need the MCR to run? I understand that

How to use C library created by MATLAB Coder codegen in C program with emxArray arguments?

北慕城南 提交于 2019-11-26 11:39:32
问题 The C function (C static library) created by codegen takes an input argument of type const emxArray_uint32_T and return values of type emxArray_struct_T . As the type suggests, input is an array of uint32 and output is an array of struct. I\'m not sure how to use this function in my C program. For the input, should I declare an array of type uint32_T or use the type emxArray_uint32_T ? For the output, because I don\'t know the size of the output array, how to declare the array of struct to