S-function error - compilation ok
1 view (last 30 days)
Show older comments
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;
}
}
}
Accepted Answer
Kaustubha Govind
on 7 Jan 2013
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 Comments
Kaustubha Govind
on 9 Jan 2013
Yes, you you move your code into the function called conv, and call conv from the Outputs pane of the S-function builder.
More Answers (0)
See Also
Categories
Find more on Block and Blockset Authoring in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!