convert to matlab function

1 回表示 (過去 30 日間)
Maria Imdad
Maria Imdad 2021 年 4 月 18 日
回答済み: Swetha Polemoni 2021 年 4 月 22 日
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 Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by