使用Matlab Coder将Matlab下的pinv函数转成C/C++
来源:互联网 发布:110kv地下变电站 知乎 编辑:程序博客网 时间:2024/06/05 03:19
环境声明:Matlab R2013a
在这里,我将Matlab下的pinv函数转成了C代码
<1>编写一个函数
function b = funcpinv( a )%#codegen%FUNCPINV Summary of this function goes here% Detailed explanation goes hereb = pinv(a);end
<2>在命令窗口,输入mex -setpu,选中一个存在的编译器
<3>在命令窗口输入coder(图形界面),回车,弹出Coder Generation Project对话框
<4>在name中输入项目名 funcpinv.prj,点OK,弹出MATLAB Coder对话框
<5>点Entry-Point Files右下角的Add files,选择文件funcpinv.m打开
<6>点变量a右边的click to define,在这里我定义了double 3*3
<7>选中Build选项卡,Output type中选择c/c++ Static Library;选中Generate code only
<8>在More settings的Speed中去掉support non-finite numbers,如果想生成C++代码,在All Settings中找到Advanced一栏,将其中的language选为C++
<9>点击Build,进行编译;点击View report,弹出Code Generation Report对话框,可以查看相应的代码
<10>在VS2005下编写测试代码:
// TestPinv.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>extern "C"{#include "funcpinv.h"};int _tmain(int argc, _TCHAR* argv[]){real_T matrix[9],matrix_pinv[9];int i = 0;for (i = 0;i < 9;i++){matrix[i] = i + 1;}for (i = 0;i < 9;i++){matrix_pinv[i] = 0;}for (i = 0;i < 9;){std::cout<<matrix[i]<<"\t"<<matrix[i+1]<<"\t"<<matrix[i+2]<<std::endl;i += 3;}std::cout<<"start to pinv"<<std::endl;funcpinv(matrix,matrix_pinv);std::cout<<"pinv is finish"<<std::endl;std::cout<<"The matrix_pinv is"<<std::endl;for (i = 0;i < 9;){std::cout<<matrix_pinv[i]<<"\t"<<matrix_pinv[i+1]<<"\t"<<matrix_pinv[i+2]<<std::endl;i += 3;}return 0;}
注:Matlab build得到的是C代码,在编译时右键点击funcpinv.c,选择Properties,在对话框中选择Precompiled Headers,Create/use Precompiled Headers一栏选择Not Using Precompiled Headers得到的结果:
参考:
1、录制的网上研讨会的MATLAB Coder视频
2、http://www.mathworks.cn/products/matlab-coder/
3、http://blog.csdn.net/fengbingchun/article/details/6793826
- 使用Matlab Coder将Matlab下的pinv函数转成C/C++
- 使用 MATLAB Coder 将 MATLAB 代码生成 C/C++ 代码
- 基于MATLAB Coder将matlab代码转换成C代码
- matlab 将wav文件转成 C 数组
- 尝试将matlab语言转成c
- 将matlab的m文件转成C语言
- Matlab Coder的使用
- 举例说明使用MATLAB Coder从MATLAB生成C/C++代码步骤
- 举例说明使用MATLAB Coder从MATLAB生成C/C++代码步骤
- 举例说明使用MATLAB Coder从MATLAB生成C/C++代码步骤
- 举例说明使用MATLAB Coder从MATLAB生成C/C++代码步骤
- 举例说明使用MATLAB Coder从MATLAB生成C/C++代码步骤
- 举例说明使用MATLAB Coder从MATLAB生成C/C++代码步骤
- MATLAB Coder从MATLAB生成C/C++代码步骤
- Matlab在字符界面下转成C语言代码
- matlab下如何调试c函数
- C/C++下调用matlab函数
- matlab下如何调试c函数
- CentOS中JAVA_HOME的环境变量设置
- 已安全化的ActiveX控件卸载时出现"DllUnregisterServer函数出错,错误代码:0x80070002"问题解决
- 加密算法及分类
- jQuery mobile 事件 swipe
- AIR 访问网络资源老提示 Unhandled ioError 错误的解决办法
- 使用Matlab Coder将Matlab下的pinv函数转成C/C++
- 作业:新浪客户端(一)新浪移动开发api介绍
- 设置安全沙箱类型
- ActionScript 3.0著名开源库 大集合
- svn merge和branch
- cacheAsBitmap
- 那些争议最大的编程观点
- register关键字在c语言和c++中的差异
- LOD地形绘制