i am new to s function,,,how to create s function from existing matlab or c code

조회 수: 7 (최근 30일)
#include<math.h>
#include<conio.h>
#include<stdio.h>
main()
{
int root,n,i,m,seq2[100];
float x,y,seq,seq1[100],sum=0,avg,pi=3.142;
clrscr();
root=36;
m=16;
i=1;
for(n=1;n<=m;n++)
{
x=((root*n*(n+1)*pi)/m);
/* printf("exp=%f",exp(-x)); */
y=-x;
printf("x=%f\t y=%f \t \n ",x,y);
seq=exp(y); /*this line is not working */
printf(" \n seq=%f",seq);
/* seq=exp(-(root*n*(n+1)*PI)/m); not getting correct output here exp() is not working
printf(" \n seq=%f",seq); */
sum=sum+seq;
seq1[i]=seq;
i=i+1;
}
avg=sum/m;
for(i=1;i<=m;i++)
{
if(seq1[i]>=avg)
{
seq2[i]=1;
}
else
{seq2[i]=0;
}
printf("\n binary=%d",seq2[i]);
}
getch();
}

답변 (1개)

Ryan G
Ryan G 2013년 1월 16일

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by