matlab2c使用c++实现matlab函数系列教程-load函数

来源:互联网 发布:赵薇事件公知 编辑:程序博客网 时间:2024/06/08 11:36

全栈工程师开发手册 (作者:栾鹏)

matlab2c动态链接库下载
matlab库函数大全
matlab2c基础教程
matlab2c开发全解教程

matlab2c调用方法:

1、下载matlab2c动态链接库
2、将matlab2c.dll、matlab2c.lib和matlab2c.h放到项目头文件目录下
3、在cpp文件中引入下面的代码

#include "Matlab2c.h"#pragma comment(lib,"Matlab2c.lib")  using namespace Matlab2c;

matlab中load函数简介

1、load函数:

从文件中读取矩阵数据

2、用法说明

A= load (‘e:\123.txt’) 从文件123.txt中读取矩阵

load的c++源码实现

从文件中加载数据
文件内容为矩阵数组形式,元素间通过空格间隔

Matrix Matlab2c::load(string path){    std::ifstream fin(path, std::ios::in);     char line[1024]={0};     string x="0";    vector<vector<double>> alldata;    while(fin.getline(line, sizeof(line),'\n'))     {         vector<double> onerow;        std::stringstream word(line);         while(word>>x)        {            onerow.push_back(std::stod(x));        }        if (onerow.size()!=0)        {            alldata.push_back(onerow);        }    }     fin.close();     Matrix p(alldata);    return p;}

load函数的使用测试

数据文件data.txt

11 22 33 44
22 33 44 55
33 44 55 66
示例代码:

#include "Matlab2c.h"#pragma comment(lib,"Matlab2c.lib")  using namespace Matlab2c;int main(){    Matrix bb=Matlab2c::load("data.txt");    cout<<bb.toString()<<endl;    system("pause");    return 0;}
阅读全文
1 0
原创粉丝点击