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
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 件のコメント
Kaustubha Govind
2013 年 1 月 9 日
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 Center および File Exchange で Block and Blockset Authoring についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!