2017-07-25 35 views
0

我通過Matlab編碼器創建了一個名爲implicit_enumeration.cpp的C++程序,它採用矩陣A和向量b作爲輸入,並返回向量zstar和概率值Vstar。我現在努力初始化主要功能:初始化Matlab編碼器的主函數

// 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

'argv []'沒有用在代碼中。不清楚你的意思是「初始化主要功能」 – user463035818

回答

0

其實,你大部分都做完了。在main(int argc,const char * const argv [])中: argc是命令行參數的個數,argv包含這些命令行參數。

例如: 如果調用test.ext something,argc是2,argv [0]是「test.exe」,argv [1]是「something」。

你的初始化將在main_implicit_enumeration()

  • DV0是你矩陣A(4 * 9矩陣 - > 36元)來完成,它是 在argInit_4x9_real_T初始化()
  • DV1是您的載體b(4矢量 - > 4種元素),並且它是在初始化argInit_4x1_real_T
  • ZSTAR是返回向量
  • VSTAR的skalar返回

問題是:你想如何將值傳遞給你的程序?從文件加載值?使用像test.ext A=1,2,3;4,5,6 b=8,9這樣的格式?