필터 지우기
필터 지우기

S-function error - compilation ok

조회 수: 3 (최근 30일)
Zoltan
Zoltan 2013년 1월 6일
Hi, i want to implement the following code into an S-function. The algorithm below separates the digits of the input number, adds 64 to the digit and the output will be a vector with these values. For some reason it doesn't want to work, i tested it using a Simulink Model which consisted of a
1.constant block
2.s-function builder
3.scope
For any input value, the scope displays 0.
*Note that at the end there is no return value, because the compiler gives 'extraneous return value' error message.
How can i resolve this problem? Thank you.
typedef unsigned char byte;
byte i,nr;
int s;
int main();
{
long newu = 0;
nr = 0;
s = 0;
if(u[1]<0)
s = 1;
while(u[1]!=0)
{
newu = newu * 10 + (u[1] % 10);
u[1]/10;
nr++;
}
for(i=nr;i>=1;i--)
{
y[i]=newu %10;
newu/=10;
}
for(i=1;i<=nr;i++)
{
switch(y[i])
{
case 0: y[i]=65;
break;
case 1:y[i]=66;
break;
case 2: y[i]=67;
break;
case 3:y[i]=68;
break;
case 4: y[i]=69;
break;
case 5:y[i]=70;
break;
case 6: y[i]=71;
break;
case 7:y[i]=72;
break;
case 8: y[i]=73;
break;
case 9:y[i]=74;
break;
}
}
}
  댓글 수: 1
Zoltan
Zoltan 2013년 1월 6일
I forgot to mention that the compilation is successful

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

채택된 답변

Kaustubha Govind
Kaustubha Govind 2013년 1월 7일
Do you call main() in the S-function Builder Outputs pane? How is the input 'u' and output 'y' passed in? I would recommend that you rename the function to something other than main and make it so that 'u' and 'y' are input/output arguments respectively.
  댓글 수: 2
Zoltan
Zoltan 2013년 1월 8일
Yes, i call main() in the S-function output pane. My problem is similar to this:
Should i make a function which does the conversion , for ex.
int conv(u); //which consists of the code above
and the main program, which calls the conv function
int main()
{
y = conv(u);
}
Also, how can i use the Legacy Code Tool to help me?
Thanks.
Kaustubha Govind
Kaustubha Govind 2013년 1월 9일
Please see this page for help on the Legacy Code Tool.
Yes, you you move your code into the function called conv, and call conv from the Outputs pane of the S-function builder.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Block and Blockset Authoring에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by