Initialize huge variables on xPC target

1 回表示 (過去 30 日間)
Chris
Chris 2012 年 1 月 11 日
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!

回答 (1 件)

Gordon Weast
Gordon Weast 2012 年 2 月 10 日
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.

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by