我通过名为implicit_enumeration.cpp的Matlab编码器创建了一个C ++程序,它将矩阵A和矢量b作为输入,并返回矢量zstar和概率值Vstar。我现在正在努力初始化主要功能:
// Include Files
#include "stdafx.h"
#include "implicit_enumeration.h"
#include "main.h"
// Function Declarations
static void argInit_4x1_real_T(double result[4]);
static void argInit_4x9_real_T(double result[36]);
static void main_implicit_enumeration();
// Function Definitions
static void argInit_4x1_real_T(double result[4])
{
int idx0;
// Loop over the array to initialize each element.
for (idx0 = 0; idx0 < 4; idx0++) {
// Set the value of the array element.
// Change this value to the value that the application requires.
result[idx0] = 1;
}
}
static void argInit_4x9_real_T(double result[36])
{
int idx0;
int idx1;
// Loop over the array to initialize each element.
for (idx0 = 0; idx0 < 4; idx0++) {
for (idx1 = 0; idx1 < 9; idx1++) {
// Set the value of the array element.
// Change this value to the value that the application requires.
if (idx0 == 0) {
if (idx1 == 0) { result[idx0 + (idx1 << 2)] = 1; }
else if (idx1 == 1) { result[idx0 + (idx1 << 2)] = 1; }
else { result[idx0 + (idx1 << 2)] = 0; }
}
else if (idx0 == 1) {
if (idx1 == 2) { result[idx0 + (idx1 << 2)] = 1; }
else if (idx1 == 3) { result[idx0 + (idx1 << 2)] = 1; }
else if (idx1 == 4) { result[idx0 + (idx1 << 2)] = 1; }
else { result[idx0 + (idx1 << 2)] = 0; }
}
else if (idx0 == 2) {
if (idx1 == 5) { result[idx0 + (idx1 << 2)] = 1; }
else { result[idx0 + (idx1 << 2)] = 0; }
}
else {
if (idx1 == 6) { result[idx0 + (idx1 << 2)] = 1; }
else if (idx1 == 7) { result[idx0 + (idx1 << 2)] = 1; }
else if (idx1 == 8) { result[idx0 + (idx1 << 2)] = 1; }
else { result[idx0 + (idx1 << 2)] = 0; }
}
}
}
}
static void main_implicit_enumeration()
{
double dv0[36];
double dv1[4];
double zstar[9];
double Vstar;
// Initialize function 'implicit_enumeration' input arguments.
// Initialize function input argument 'A'.
// Initialize function input argument 'b'.
// Call the entry-point 'implicit_enumeration'.
argInit_4x9_real_T(dv0);
argInit_4x1_real_T(dv1);
implicit_enumeration(dv0, dv1, zstar, &Vstar);
}
int main(int argc, const char * const argv[])
{
// Initialize the application.
// You do not need to do this more than one time.
// Invoke the entry-point functions.
// You can call entry-point functions multiple times.
main_implicit_enumeration();
return 0;
}
具体来说,我想知道如何将argv []初始化为矩阵A和向量b。是否有必要设置命令参数,即使我已经通过函数argInit_4x9_real_T()和argInit_4x1_real_T()初始化了矩阵A和向量b?如果是,如何将矩阵和向量包含为命令参数?我检查的例子总是显示单个整数或实数值,但不显示矩阵或向量。 提前谢谢!
答案 0 :(得分:0)
实际上,你基本上已经完成了。
在main中(int argc,const char * const argv []): argc是命令行参数的数量,argv包含这些命令行参数。
实施例:
如果你打电话给 let tapGesture = UITapGestureRecognizer.init(target: self, action: #selector(clickToOpen))
self.view.addGestureRecognizer(tapGesture)
,argc是2,argv [0]是“test.exe”,argv [1]是“某事”。
您的初始化在main_implicit_enumeration()
中完成问题是:您希望如何将值传递给您的程序?从文件加载值?使用test.ext something
?