Hi
convert to matlab function
1 次查看(过去 30 天)
显示 更早的评论
Hi Everyone,
I have this small function written in C++. I will be very greatful if someone can help me convert it to matlab.
string InputA,InputB,InputC,InStrB;
int tempIntA,tempIntB,IA[128],IB[128];
float OutDouA,OutDouB,OutDouC,OutDouD,OutDouE,InDouA,AE,Pi[128],Ci[128],PiCi[128];
InputA="1100000110000100011101000000100011000111110011111001111100010001";
InputB="1111100110110000101111101101100111011000110001010100111111001111";
double Corre (string InStrA, string InStrB, double InDouA)
{
OutDouA=0.0;
for(int i=0;i<InStrA.length();i++)
{
if(InStrA.at(i)=='1'){IA[i]=1;}if(InStrA.at(i)=='0'){IA[i]=0;}
if(InStrB.at(i)=='1'){IB[i]=1;}if(InStrB.at(i)=='0'){IB[i]=0;}
Pi[i]=(double)IA[i]-InDouA;
Ci[i]=(double)IB[i]-InDouA;
PiCi[i]=Pi[i]*Ci[i];
OutDouA=OutDouA+PiCi[i];
OutDouB=OutDouB+Pi[i]*Pi[i];
OutDouC=OutDouC+Ci[i]*Ci[i];
}
//cout<<"OutDouA: "<<OutDouA<<endl;cout<<"OutDouB: "<<OutDouB<<endl;cout<<"OutDouC: "<<OutDouC<<endl;
OutDouD=sqrt(OutDouB)*sqrt(OutDouC);//cout<<"OutDouD: "<<OutDouD<<endl;
OutDouE=OutDouA/OutDouD;
cout<<"Correlation Coefficient: "<<OutDouE<<endl;
return(OutDouE);
}
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!