# convert to matlab function

1 view (last 30 days)
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,IB;
float OutDouA,OutDouB,OutDouC,OutDouD,OutDouE,InDouA,AE,Pi,Ci,PiCi;
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);
}

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