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!