S-function error - compilation ok

3 次查看(过去 30 天)
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;
}
}
}

采纳的回答

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 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by