convert to matlab function

1 次查看(过去 30 天)
Maria Imdad
Maria Imdad 2021-4-18
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);
}

回答(1 个)

Swetha Polemoni
Swetha Polemoni 2021-4-22
Hi
You may find MATLAB Onramp course useful for converting your code to MATLAB function.

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by