博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
matlab-mex 示例代码(mxCreateDoubleMatrix)
阅读量:2050 次
发布时间:2019-04-28

本文共 1993 字,大约阅读时间需要 6 分钟。

 

/********************************************************************* * Demo.cpp * * This file shows the basics of setting up a mex file to work with * Matlab.  This example shows how to use 2D matricies.  This may *  * Keep in mind: * <> Use 0-based indexing as always in C or C++ * <> Indexing is column-based as in Matlab (not row-based as in C) * <> Use linear indexing.  [x*dimy+y] instead of [x][y] * * For more information, see my site: www.shawnlankton.com * by: Shawn Lankton * ********************************************************************/#include 
#include
/* Definitions to keep compatibility with earlier versions of ML */#ifndef MWSIZE_MAXtypedef int mwSize;typedef int mwIndex;typedef int mwSignedIndex;#if (defined(_LP64) || defined(_WIN64)) && !defined(MX_COMPAT_32)/* Currently 2^48 based on hardware limitations */# define MWSIZE_MAX 281474976710655UL# define MWINDEX_MAX 281474976710655UL# define MWSINDEX_MAX 281474976710655L# define MWSINDEX_MIN -281474976710655L#else# define MWSIZE_MAX 2147483647UL# define MWINDEX_MAX 2147483647UL# define MWSINDEX_MAX 2147483647L# define MWSINDEX_MIN -2147483647L#endif#define MWSIZE_MIN 0UL#define MWINDEX_MIN 0UL#endifvoid mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){//declare variables mxArray *a_in_m, *b_in_m, *c_out_m, *d_out_m; const mwSize *dims; double *a, *b, *c, *d; int dimx, dimy, numdims; int i,j;//associate inputs a_in_m = mxDuplicateArray(prhs[0]); b_in_m = mxDuplicateArray(prhs[1]);//figure out dimensions dims = mxGetDimensions(prhs[0]); numdims = mxGetNumberOfDimensions(prhs[0]); dimy = (int)dims[0]; dimx = (int)dims[1];//associate outputs c_out_m = plhs[0] = mxCreateDoubleMatrix(dimy,dimx,mxREAL); d_out_m = plhs[1] = mxCreateDoubleMatrix(dimy,dimx,mxREAL);//associate pointers a = mxGetPr(a_in_m); b = mxGetPr(b_in_m); c = mxGetPr(c_out_m); d = mxGetPr(d_out_m);//do something for(i=0;i

 

转载地址:http://fzwlf.baihongyu.com/

你可能感兴趣的文章
梦飞 —— 述:我只是一个普通农民家的孩子,但我有一个梦想
查看>>
图解HTTP(二)—— 简单的HTTP协议
查看>>
程序员的数学(四)—— 数学归纳法,如何征服无穷数列
查看>>
不是技术人员也能看懂云计算、大数据、人工智能
查看>>
图解HTTP(三)—— HTTP报文内的HTTP信息
查看>>
图解HTTP(四)—— 返回结果的HTTP状态码
查看>>
JavaWeb高级编程(五)—— 使用会话来维持HTTP状态
查看>>
Intellij IDEA使用(十五)—— 如何在IDEA中一个Tomcat启动多个项目和多个Tomcat启动多个项目
查看>>
图解HTTP(五)—— 与HTTP协作的Web服务器
查看>>
程序员的数学(五)—— 排列组合,解决计数问题的方法
查看>>
前后端分离实践(四)—— 使用vue-cli搭建前端展示层并用mock模拟测试数据
查看>>
前后端分离实践(六)—— 前端与后端在生产环境中的分离部署
查看>>
启航 —— 记 —— 第二次自考的反思:自考与自我改造的困境
查看>>
数据结构与算法(三)——线性表
查看>>
Java8学习笔记(一)—— 函数式编程的四个基本接口
查看>>
Java8学习笔记(二)—— Lambda表达式
查看>>
Java8学习笔记(三)—— Optional类的使用
查看>>
Java8学习笔记(四) —— Stream流式编程
查看>>
Java8学习笔记(五)—— 方法引用(::双冒号操作符)
查看>>
数据结构与算法(四)—— 栈与队列
查看>>