Hi,
I'm using matlab coder to speed up time. However, I have an array which in normal matlab becomes ArrayLarge: 31x1x441, 109368 double.
But when I use coder and compile a mex file, my Matlab craches. With the Mex file I have generated I can genrate the same array but only up to aboute ArrayLarge: 31x1x246, 61008 double, before it crashes.
But how can I compile an mex file which can create the ArrayLarge: 31x1x441, 109368 double, which is generated with the regular matlab code. Is it some settings in the MatLab coder which I can change? (It is not memory problem for the comuter as the coputer enables to create the ArrayLarge on original MatLab 2022a).

 採用された回答

Walter Roberson
Walter Roberson 2023 年 4 月 16 日

0 投票

I suspect that you are reaching the stack size limit.
If you are generating for real-time work, then you would need to increase the stack size limit.
If you are not generating for real-time work, then enable dynamic memory allocation for the array; https://www.mathworks.com/help/coder/ug/minimize-dynamic-memory-allocation.html

3 件のコメント

Martin Andersson
Martin Andersson 2023 年 4 月 16 日
編集済み: Martin Andersson 2023 年 4 月 16 日
What do you mean with "real-time work"?
I use a matlab code (*.m) call the mex and do a big for loop in the mex file. Is not generating for real-time work and I should look at enable dynamic memory allocation.
Currently I have selected Enable varible sizing, set option "For arrays max size at or above thresshold" Dynamic memory allcation threshold "1 000 000" Array layout "Column-major, Enable highlight potential row-major issues. Not selected "Preserve array dimentions and satt "Stack usage max" to 2 000 000.
Is this good, could I change somthing in the memory settings to be able to run the mex file.
Sorry I'm a novise at this. Is it also posible to calcualte the size of the ArrayLarge: 31x1x441, 109368 double in bytes?
Walter Roberson
Walter Roberson 2023 年 4 月 16 日
ArrayLarge = zeros(31, 1, 441);
numel(ArrayLarge)
ans = 13671
whos ArrayLarge
Name Size Bytes Class Attributes ArrayLarge 31x1x441 109368 double
So the 109368 is already bytes, not number of elements.
Martin Andersson
Martin Andersson 2023 年 4 月 16 日
編集済み: Martin Andersson 2023 年 4 月 16 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

製品

リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by