简体   繁体   English

如何在C ++中调用函数

[英]How can I call a function in C++

I have called a C++ function from matlab. 我从matlab调用了C ++函数。
I do not know how to run in C++ 2010 我不知道如何在C ++ 2010中运行

in matlab the function command is 在matlab中,功能命令是

>> y = kalman01(z);

in C++, I know only this one 在C ++中,我只知道这一个

void kalman01(const double z[2], double y[2])

so How I use kalman01.cpp to pass an input to get output and display output y ? 那么我如何使用kalman01.cpp传递输入以获取输出并显示输出y

you have to write the function code to do operation on z array to obtain y array. 您必须编写函数代码以对z数组进行操作以获得y数组。 The input of the function are an array z, that is declared const and then you can't modify it, and an array y, that contains the result of the operation performed in the function. 函数的输入是一个数组z,它声明为const,然后您不能对其进行修改;而它的数组y,包含在函数中执行的操作的结果。 Now I write a simple example: 现在我写一个简单的例子:

void kalman01(const double z[2], double y[2])
{
     y[0] = z[0] * 2;
     y[1] = z[1] * 2;
     cout << y[0] << "  " << y[1] << endl;
}

this function take z array e return an array with elements multiplied by 2. In main function, you write this: 该函数采用z array e返回一个元素乘以2的数组。在main函数中,您可以这样编写:

double y[2] = {0};
kalman01(z,y);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM