필터 지우기
필터 지우기

Structure or array for S-function input, output and parameters?

조회 수: 3 (최근 30일)
Remus Mihail Prunescu
Remus Mihail Prunescu 2012년 7월 25일
Hi,
What is faster and what do you recommend?
I have a C S-function with 14 inputs. 1. Right now I am using a single port and I see the input as an array. I have 14 #define in order to help selecting the right input: for example #define U_IDX_FLOW_WATER 0 and then I select it as u[U_IDX_FLOW_WATER]. It helps understanding the code better than using a plain number.
2. I just came across passing structures to S-functions and, I guess, I could select my input like u->flow_water and forget about the hardcoding that I did before.
Is there a performance penalty when using approach 2?
Thanks, Remus.

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2012년 7월 25일
I can't imagine there being a major difference in Simulink performance between #1 and #2 - they are equivalent to writing two C functions - one that takes several function arguments and the other takes one structure argument with each field represent arguments from the first function. So it boils down to more of a C question - is one more efficient that the other in C?
However, from my experience, using structure/bus signals to combine similar signals is good modeling practice.
  댓글 수: 3
Remus Mihail Prunescu
Remus Mihail Prunescu 2012년 7월 25일
편집: Remus Mihail Prunescu 2012년 7월 25일
Actually it's easy to do:
typedef struct {
real_T mass;
real_T a_t;
real_T b_t;
real_T c_t;
} PX;
....
PX *x = (PX*)ssGetContStates(S);
PX *dx = (PX*)ssGetdX(S);
:D. Thanks!
Kaustubha Govind
Kaustubha Govind 2012년 7월 25일
Structure types are only supported for inputs, output and parameters, not states. But looks like you've found a solution anyway. :)

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by