How to use trained neural network as function using MATLAB coder?

2 次查看(过去 30 天)
I've trained a simple neural network that just multiply 4 numbers and gives 1 number as an output.
( output(x0) = in1(x0)*in2(x0)*in3(x0) *in4(x0)).
or description:
Capture1.JPG
My neural net has 4 inputs, and 1 output, [10 10] is the hidden layer. I used 'genFunction' to generate a .m file out of network.then I used MATLAB coder to generate C++ function. I generate the code with following input types: input types:
Capture.JPG
My problem is when I test the C++ code it only gives the 2 first samples for the output.
I store my entries in a std:: vector which has size of 400 (each input size is 100)
I've done the following so far (no desirable output though):
std::vector<double> Multiplier(std::vector<double>& input)
{
double* X_data = new double[input.size()];
X_data = vec2ar(input);
int X_size[2];
X_size[0] = 4;
X_size[1] = 100;
double* Y_data = new double[input.size()];
int Y_size[100];
While the original was:
void multiplier(const double X_data[], const int X_size[2], double Y_data[], int Y_size[2])
{
double Xp1_data[800];
int Xp1_size[2];
int j;
double a1_data[2000];
int coffset;
int a1_size[2];
int boffset;
double tmp_data[2000];
int k;
double b_a1_data[2000];
And for getting the output:
std::vector<double> output;
output = ar2vec(Y_data);
return output;
All I want is we have 4 vectors and give them to this function simply just multiply corresponding samples as shown in 'description' (in my case we have 4 vectors of size 100, and we expect an output with size 100).
And for ar2vec and vec2ar functions:
std::vector<double> ar2vec(double arr[])
{std::vector<double> vec;
copy(&arr[0], &arr[100], std::back_inserter(vec));
return vec;
}
double* vec2ar(std::vector<double> vec){
double * arr = new double[vec.size()];
copy(vec.begin(), vec.end(), arr);
return arr;
}
Could you please help me to fix my problem?
Regards.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by