Initialize huge variables on xPC target
1 view (last 30 days)
Show older comments
I am looking for a possibility to initialize huge variables on the xPC target. That variable should contain a huge matrix and be is required to read out few values and overwrite some values at each time step. It should not forget the values I wrote into it while the program is running.
I tried with defining it as persistent variable in an embedded m-file - and basically it works, but of course it is not initilized at the first start. Therefore I put a
if isempty(varialename) variablename = zeros(dim1,dim2)
in the m-file.
As this variable is too big, that command takes too long and I get a cpu overload error.
Thats why I want to initilize it before the system started... Any ideas?
Is there a compiler command allowing this? Or even something simpler? Thanks!
0 Comments
Answers (1)
Gordon Weast
on 10 Feb 2012
To satisfy all your requirements, you might need to write your own S-function. Then use the target disk to save the values at stop time and restore them in mdlStart when you start the model again.
You can use file system calls inside your S-function. Do the file IO in mdlStart and mdlTerminate. You can use malloc() to allocate the buffer. Save the pointer in a P-work variable. Match allocation in mdlStart with freeing in mdlTerminate or you'll see a memory leak.
This does require that you have a disk with a FAT file system on it. You'll be able to read/write the file with the data from the host to set up the initial values and recover the final values.
0 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!