How can I use 2D Output with S-Function Builder

5 次查看(过去 30 天)
Hello,
I need to get three 2D array as output from an S-Function Builder but I don't know how can I write to these arrays in my C-Code. Here is my S-Function Builder parameters :
If I try something like
for (row = 0; row < 480; row++)
{
for (col = 0; col < 640; col++)
{
R[row][col] = r_buffer[row][col];
G[row][col] = g_buffer[row][col];
B[row][col] = b_buffer[row][col];
}
}
I get errors like this :
UDPMsgToImg_wrapper.c:90:23: error: subscripted value is neither array nor pointer nor vector
R[row][col] = r_buffer[row][col];
^
UDPMsgToImg_wrapper.c:91:23: error: subscripted value is neither array nor pointer nor vector
G[row][col] = g_buffer[row][col];
^
UDPMsgToImg_wrapper.c:92:23: error: subscripted value is neither array nor pointer nor vector
B[row][col] = b_buffer[row][col];
Which seems to be logical because if I look into the file 'UDPMsgToImg_wrapper.c', R, G and B are defined as simple pointers :
void UDPMsgToImg_Outputs_wrapper(const uint32_T *UDPMsg,
const uint16_T *msgLength,
uint8_T *R,
uint8_T *G,
uint8_T *B,
const uint16_T *imgWidth, const int_T p_width0,
const uint16_T *imgHeight, const int_T p_width1)
{
}
Have you an idea to do this ?
Thanks !

回答(1 个)

Frédéric Naud-Dulude
* Note1: Matrix signals are stored in column major order.
* Note2: Access each matrix element by one index not two indices.
* For example, if the output signal is a [2x2] matrix signal,
* - -
* | y[0] y[2] |
* | y[1] y[3] |
* - -
* Output elements are stored as follows:
* y[0] --> row = 0, col = 0
* y[1] --> row = 1, col = 0
* y[2] --> row = 0, col = 1
* y[3] --> row = 1, col = 1
*/
More on this here :
https://stackoverflow.com/questions/11525701/how-can-i-create-an-s-function-in-simulink-with-an-input-port-that-is-a-2d-array

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by