Generating code for a single element array

We have a model that interfaces to a legacy variable that is defined as a single element array. The variable's definition comes from a legacy header file, thus we have created our input data object as a Simulink.Signal using the ImportFromFile storage class.
If I set the signal Dimensions to 2 and use a demux or Selector to select the 1st element I get the correct generated code, something like:
temp = mySingleElementArray[0];
However, if I give it a dimension of 1 (which is what it should be) then it is treated as a scalar; even if I put a demux or Selector on the signal. So the generated code is:
temp = mySingleElementArray;
Which loads the address of the array into temp.
How do I define the input signal object so the code treats this variable correctly?

 Accepted Answer

TAB
TAB on 1 May 2012
You can set the Storage class of signal ImportedExternPointer. In your legacy code, write the actual definition of this pointer and assign the address of your array element.
Anyhow! it is not clear why you are using a scalar as a single element array in your legacy code.

1 Comment

yes this approach works, which is what we were using, it just requires some special processing on our part.
The legacy s/w is configurable so this variable may have more than one element depending on the configuration, for example a cam sensor reading. If you have an inline 4 cylinder engine there is only one cam, if you have a v8 there are 2 cams. This configuration is done at compile time.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Tags

Asked:

on 30 Apr 2012

Community Treasure Hunt

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

Start Hunting!