簡體   English   中英

從Matlab Coder初始化主要功能

[英]Initializing main function from Matlab Coder

我通過Matlab編碼器創建了一個C ++程序,名為hidden_​​enumeration.cpp,該程序將矩陣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,也需要設置命令參數嗎? 如果是,如何將矩陣和向量作為命令參數? 我檢查的示例始終顯示單個整數或實數值,但不顯示矩陣或向量。 先感謝您!

實際上,您基本上已經完成了。

在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的格式test.ext A=1,2,3;4,5,6 b=8,9

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM