C Matlab Mex网关文件,打印phrs

时间:2020-12-21 18:51:12

I want to print the values of phrs to terminal and check their data type. I thought I got the first part:

我想将phrs的值打印到终端并检查它们的数据类型。我以为我得到了第一部分:

mexPrintf("Value: %d\n",prhs[0]);

But that's giving me junk. What am I missing? (Probably something obvious) Is there a way to check data types and print them out?

但这给了我垃圾。我错过了什么? (可能是显而易见的事情)有没有办法检查数据类型并打印出来?

2 个解决方案

#1


1  

To check prhs date type, i think you can use mxGetClassName(prhs[0]). To print its value, you need to dereference it again, as I remember correctly. For example:

要检查prhs日期类型,我认为你可以使用mxGetClassName(prhs [0])。要打印它的值,你需要再次取消引用它,正如我没记错的那样。例如:

double* data = mxGetPr(prhs[0]);
mexPrintf("Value: %f\n",data[0]);

Note, mxGetPr, returns pointer to double, so left it in this example.

注意,mxGetPr返回指向double的指针,因此在此示例中保留它。

#2


1  

prhs is an array of pointers to mxArrays corresponding to your inputs. Depending on the type of your input you may use:

prhs是一个指向与输入相对应的mxArrays的指针数组。根据您输入的类型,您可以使用:

  • if your input is a scalar:
  • 如果您的输入是标量:

double input = mxGetScalar(prhs[0]); printf("Value: %f\n",input);

double input = mxGetScalar(prhs [0]); printf(“值:%f \ n”,输入);

  • if your input is an array:
  • 如果您的输入是一个数组:

double* input = mxGetPr(prhs[0]); printf("Value: %f\n",input[0]);

double * input = mxGetPr(prhs [0]); printf(“值:%f \ n”,输入[0]);

to get a pointer to your array of values, but here we print only the first value. You can use mxGetDimensions() to get the dimensions of the array.

获取指向值数组的指针,但在这里我们只打印第一个值。您可以使用mxGetDimensions()来获取数组的尺寸。

#1


1  

To check prhs date type, i think you can use mxGetClassName(prhs[0]). To print its value, you need to dereference it again, as I remember correctly. For example:

要检查prhs日期类型,我认为你可以使用mxGetClassName(prhs [0])。要打印它的值,你需要再次取消引用它,正如我没记错的那样。例如:

double* data = mxGetPr(prhs[0]);
mexPrintf("Value: %f\n",data[0]);

Note, mxGetPr, returns pointer to double, so left it in this example.

注意,mxGetPr返回指向double的指针,因此在此示例中保留它。

#2


1  

prhs is an array of pointers to mxArrays corresponding to your inputs. Depending on the type of your input you may use:

prhs是一个指向与输入相对应的mxArrays的指针数组。根据您输入的类型,您可以使用:

  • if your input is a scalar:
  • 如果您的输入是标量:

double input = mxGetScalar(prhs[0]); printf("Value: %f\n",input);

double input = mxGetScalar(prhs [0]); printf(“值:%f \ n”,输入);

  • if your input is an array:
  • 如果您的输入是一个数组:

double* input = mxGetPr(prhs[0]); printf("Value: %f\n",input[0]);

double * input = mxGetPr(prhs [0]); printf(“值:%f \ n”,输入[0]);

to get a pointer to your array of values, but here we print only the first value. You can use mxGetDimensions() to get the dimensions of the array.

获取指向值数组的指针,但在这里我们只打印第一个值。您可以使用mxGetDimensions()来获取数组的尺寸。