matlabコーダーから生成されたC++コードがありますが、配列のサイズを正しく設定する方法がわかりません。この配列のサイズを設定する方法C++
static emxArray_real_T *argInit_d7351x5_real_T()
{
emxArray_real_T *result;
static int iv0[2] = { 2, 5 };
int idx0;
int idx1;
// Set the size of the array.
// Change this size to the value that the application requires.
result = emxCreateND_real_T(2, *(int (*)[2])&iv0[0]);
// Loop over the array to initialize each element.
for (idx0 = 0; idx0 < result->size[0UL]; idx0++) {
for (idx1 = 0; idx1 < 5; idx1++) {
// Set the value of the array element.
// Change this value to the value that the application requires.
result->data[idx0 + result->size[0] * idx1] = argInit_real_T();
}
}
return result;
}
//
// Arguments : void
// Return Type : double
//
static double argInit_real_T()
{
return 1.0;
}
Iは、10x5のマトリクスを必要は10 [0] IV0を変更するために、それが正しい、argInit_real_T関数からデータを埋め? int(*)[2]コマンドはどのように機能しますか?
struct emxArray_real_T
{
double *data;
int *size;
int allocatedSize;
int numDimensions;
boolean_T canFreeData;
};
emxArray_real_T *emxCreateND_real_T(int numDimensions, int *size)
{
emxArray_real_T *emx;
int numEl;
int i;
emxInit_real_T(&emx, numDimensions);
numEl = 1;
for (i = 0; i < numDimensions; i++) {
numEl *= size[i];
emx->size[i] = size[i];
}
emx->data = (double *)calloc((unsigned int)numEl, sizeof(double));
emx->numDimensions = numDimensions;
emx->allocatedSize = numEl;
return emx;
}
を初期化するだろう変数を定義することが可能ですC++の関数のどこにでも置くことができます。例えば、forループが始まるところでは、for(int idx0 = 0; idx0 < result->サイズ[0UL]; idx0 ++) 'です。変数をできるだけローカルに保つことは、しばしば良い方法と考えられます。これはバグの数を減らす傾向があります。 – patrik