Hi, I'm trying to implement a test where I create an executable from a Matlab function where the executable takes in a variable number of command line arguments and then sends them into the Matlab function. Currently the Matlab function is trivial (just returns the mean), however I'm having trouble writing my main.c function.
I've gotten the code working where I see that I'm correctly getting the data into the c-code (If I use the display command I can see the inputs.), however when I try to get that data into an array and then the array into the Matlab function I get a segmentation fault. I think that I'm messing up something in terms of how I'm creating the array, or how I'm sending the array into the Matlab function. I tried using 'emxArray_real_T', as per the run_atoms example, but wasn't able to get that to work. My knowledge of C is limited, and while I've put a lot of work into this, I haven't been able to get this to work.
The code I've been using is below; if someone is able to help me out with this it would be greatly appreciated!
Thanks, David
/*** test3_main.c *************************************************/#include <stdio.h>#include "codegen/exe/test3/test3.h"#include "codegen/exe/test3/test3_emxAPI.h"int main(int argc, char **argv){ int size_array = argc - 1; int index; double array_vals[size_array]; for( int i = 1; i < argc; ++i ) { index = i - 1; array_vals[index] = atof(argv[i]); } double *result; test3(array_vals,result); printf("%f \n",result);}/************************************************************//*** test3.m *************************************************/function result = test3(data, result) %#codegen
result = mean(data);/************************************************************/cfg = coder.config('exe');cfg.DynamicMemoryAllocation = 'AllVariableSizeArrays';codegen test3 test3_main.c -args {coder.typeof(0,[1 inf],1), double(10)} -config cfg./test3 4 5 6 7Segmentation fault
Best Answer