convert to matlab function

1 view (last 30 days)
Maria Imdad
Maria Imdad on 18 Apr 2021
Answered: Swetha Polemoni on 22 Apr 2021
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);
}

Answers (1)

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

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!