I need to return some arrays inside a time based simulation from a C Code to Matlab.
I tried from a mex function that work and C Caller blocks that partially work, let me explain :
When calling the C function that do the simulation by itself (calling it once, without the timestep of simulink linked), it works. Now, I would like instead of one C call where all the time based simulation is done inside C, to dynamically call the C function for every time step of simulink (manually put inside config parameters). That means deleting a for loop that corresponds to the timestep in the C function and make the code behaves as each call of the simulation function return one pointer of the array instead of the entire array.
When comparing the non-linked timestep with the linked timestep model, when seeing the arrays in the workspace environment with to workspace blocks, instead of having for a 1D array, each data in one row, I have a diagonal matrix, where the datas are saved in diagonal, colums and rows now corresponding to time. It gives memory issues and given the size of my simulation, it can't be processed for the entire simulation. Also it seems to increase my windows temp files for every simulation, not really deleting it even though I use clearvars at the initFcn in the callbacks tab of Simulink.
Is this because of how C Caller work ? Am I missing some comprehension on how arrays are saved and returned ? Are there other options, like S functions ?
To put it more simply, if I want some 1D array, like [1,2,3] in C to be returned as each data corresponds to one timestep in Simulink, how can I do it while avoiding a diagonal matrix returned instead ?