Accessing an externally defined array's elements in the generated code

조회 수: 1 (최근 30일)
Macko
Macko 2013년 1월 15일
Hi,
I need to define an interface signal to my model, that will actually get data from the second element of an external uint16 array. My problem is that I have no idea how to specify this...
What I woold like to achive is something like this:
mod_Y.out1 = myArray[1];
where myArray is a 10-elements array, defined in another module.
Any suggestion is more than welcome! Many thanks in advance!

답변 (1개)

TAB
TAB 2013년 1월 15일
Create a poiter to you data in your code.
uint16 *myArrayPtr = &array[1];
Now in your model, for the signal which read this array element, set name of signal to myArrayPtr and its the storage class to ImportedExternPointer.
In the generated code this signal will be generated as extern pointer
extern uint16 *myArrayPtr;
So this will return the value of array[1] when being read.
mod_Y.out1 = *myArrayPtr;
  댓글 수: 2
Macko
Macko 2013년 1월 15일
Thanks, Tab! However, this will return the value of myArray[0] instead of myArray[1].
TAB
TAB 2013년 1월 16일
We are initializing pointer with the address of array[1]. So offcourse pointer will give the value of array[1].

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by