mex2 Inputs and Outputs
来源:互联网 发布:如何查询淘宝买家等级 编辑:程序博客网 时间:2024/05/16 04:08
1. 新建normalizecolsmx.c文件
/* normalizecolsmx.c Normalize the columns of a matrixSyntax: B = normalizecols(A)or B = normalizecols(A,p)The columns of matrix A are normalized so that norm(B(:,n),p) = 1. */#include <math.h>#include "mex.h"#define IS_REAL_2D_FULL_DOUBLE(P) (!mxIsComplex(P) && mxGetNumberOfDimensions(P) == 2 && !mxIsSparse(P) && mxIsDouble(P))#define IS_REAL_SCALAR(R) (IS_REAL_2D_FULL_DOUBLE(P) && mxGetNumberOfElements(P) == 1)void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){#define B_OUTplhs[0]#define A_INprhs[0]#define P_INprhs[1]double *B, *A, p, colnorm;int M, N, m, n;if( nrhs < 1 || nrhs > 2)mexErrMsgTxt("Wrong number of input arguments.");else if(nlhs > 1)mexErrMsgTxt("Too many output arguements");if( !IS_REAL_2D_FULL_DOUBLE(A_IN) )mexErrMsgTxt("A must be a real 2D full double array.");if( nrhs == 1)p = 2.0;elsep = mxGetScalar(P_IN);M = mxGetM(A_IN);N = mxGetN(A_IN);A = mxGetPr(A_IN);B_OUT = mxCreateDoubleMatrix(M, N, mxREAL);B = mxGetPr(B_OUT);for(n = 0; n < N; n++){for(m = 0, colnorm = 0.0; m < M; m++)colnorm += pow(A[m + M*n], p);colnorm = pow( fabs(colnorm), 1.0/p);for(m = 0; m < M; m++)B[m + M * n] = A[m + M * n]/colnorm;}return ;}
2. 编译normalizecolsmx.c 文件
mex normalizecolsmx.c
3. 新建normalizecols.m文件,在此文件使用c文件编译出来的mexw64文件
%normalizecols.mfunction B = normalizecols(A, p) if nargin < 2 if nargin < 1 error('Not enough input arguements'); end p = 2; end if ~isreal(A) || ndims(A) ~= 2 || issparse(A) || ~isa(A, 'double') error('A must be a real 2D full double array.'); elseif ~ isreal(p) || ~isa(p, 'double') || numel(p) ~= 1 error('P must be a real double scalar.'); end B = normalizecolsmx(A, p);end
4. 在命令行中使用normalizecols.m, 输入
0 0
- mex2 Inputs and Outputs
- Video4Linux2 part 4: inputs and outputs
- 171116 Keras-Multiple inputs and outputs
- deal - Distribute inputs to outputs matlab
- tensorflow编程: Inputs and Readers
- tf API 研读4:Inputs and Readers
- Understanding Single-Ended, Pseudo-Differential and Fully-Differential ADC Inputs
- Disabling Auto-Correct And Auto-Capitalize Features On iPhone Inputs
- SUMO文档065:Reading SUMO networks and outputs withPython (sumolib)
- Demonstration of how NOT to implement edge detection and asynchronous inputs to a state machine
- Reads information from the file and outputs it onto the screen
- Vertex Shader Inputs【转】
- 13 Controlled Inputs
- 2.2. Multiple Inputs
- read unknown number of inputs
- DE23 Use with Impulse Inputs
- outputs from ping6/traceroute6/nmap6....
- Reading an unknow number of Inputs
- 关于字符集的若干问题总结
- 字符集典型场景
- mex 1 hello,world
- 一些站外很有价值的博客
- Range Sum Query 2D - Immutable
- mex2 Inputs and Outputs
- Spring MVC controller带参数跳转
- test
- TensorLayer : 最新深度学习与增强学习库
- 数据库SQL 优化
- OpenJ_Bailian 2755 神奇的口袋
- HDU 1180 诡异的楼梯(BFS)
- 线程 —— 定时器介绍
- 按门铃启动 Webcam照相并将编码存入Bluemix Cloudant 数据库