How to convert C++ code into Matlab. How to write the below given part of code into matlab

조회 수: 2 (최근 30일)
double logistic(double x)
{
if(x > 100.0) x = 1.0;
else if (x < -100.0) x = 0.0;
else x = 1.0/(1.0+exp(-x));
return x;
}
void ComputeFeedForwardSignals(double* MAT_INOUT,double* V_IN,double* V_OUT, double* V_BIAS,int size1,int size2,int layer)
{
int row,col;
for(row=0;row < size2; row++)
{
V_OUT[row]=0.0;
for(col=0;col<size1;col++)V_OUT[row]+=(*(MAT_INOUT+(row*size1)+col)*V_IN[col]);
V_OUT[row]+=V_BIAS[row];
if(layer==0) V_OUT[row] = tanh(V_OUT[row]);
if(layer==1) V_OUT[row] = logistic(V_OUT[row]);
}
}
  댓글 수: 1
Guillaume
Guillaume 2015년 8월 18일
A basic knowledge of C and matlab is enough to translate the above code, so what difficulties are you encountering?

댓글을 달려면 로그인하십시오.

채택된 답변

Titus Edelhofer
Titus Edelhofer 2015년 8월 18일
Hi Vandana,
that should be straight forward:
function y = logistic(x)
y = zeros(size(x));
y(x>100) = 1.0;
idx = x>=-100 & x<=100;
y(idx) = 1.0./(1.0+exp(-x));
and the main function
function V_OUT = ComputeFeedForwardSignals(MAT, V_IN, V_BIAS, layer)
V_OUT = MAT * V_IN + V_BIAS;
switch layer
case 0
V_OUT = tanh(V_OUT);
case 1
V_OUT = logistic(V_OUT);
otherwise
error('Unknown value for layer.')
end
Titus

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by