C++和Matlab最常用的编程技能,实现复杂算法的基础
2017-02-09 11:40
826 查看
1、文件读写
(1)获得文件夹下所有的文件
void getFiles(string path, vector<string>& files)
{
//文件句柄
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
//如果是目录,迭代之
//如果不是,加入列表
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
}
else
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
(2)读取某个文件的数据
void ReadData(string filepath)
{
ifstream fin(filepath);
string sx,sy,sz;
while (fin >> sx>>sy>>sz)
{
//cout << sx <<" "<< sy <<" "<< sz << endl;
x = atof(sx.c_str());
y = atof(sy.c_str());
z = atof(sz.c_str());
}
}
(3)输出数据到某个文件
void OutputFile()
{
for (int i = 0; i < curvenum; i++)
{
if (curvelist[i].length <=2)
continue;
int point_num_incurve=curvelist[i].point_list.size();
Curve3d curve = curvelist[i];
char outputfilename[300];
sprintf_s(outputfilename, 300, "D:\\CurvesOutput\\x1\\curve%d.off", i);
//定制文件名
std::ofstream out(outputfilename, std::ios::out);
out << "OFF" << endl;
out << curvelist[i].length << " 0 " << "0 " << endl;
bool isfirst = true;
Point3d point_last;
for (int j = 0; j < point_num_incurve; j++)
{
int pointindex = curve.point_list[j];
Point3d point = pointlist[pointindex];
if (point.valid == 0)
{
continue;
}
out << point.x << " " << point.y << " " << point.z << endl;
}
out.close();
}
}
2、超大矩阵
vector<vector<double>> M1(a1, vector<double>(b1, 0));
建立一个a1*b1的超大矩阵,全部赋值为0,可以非常大
3、基本算法
可以参考我原来写过的算法总结,包括各种基本数据结构的使用等等
点击打开链接
(1)获得文件夹下所有的文件
void getFiles(string path, vector<string>& files)
{
//文件句柄
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
//如果是目录,迭代之
//如果不是,加入列表
if ((fileinfo.attrib & _A_SUBDIR))
{
if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
}
else
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name));
}
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
(2)读取某个文件的数据
void ReadData(string filepath)
{
ifstream fin(filepath);
string sx,sy,sz;
while (fin >> sx>>sy>>sz)
{
//cout << sx <<" "<< sy <<" "<< sz << endl;
x = atof(sx.c_str());
y = atof(sy.c_str());
z = atof(sz.c_str());
}
}
(3)输出数据到某个文件
void OutputFile()
{
for (int i = 0; i < curvenum; i++)
{
if (curvelist[i].length <=2)
continue;
int point_num_incurve=curvelist[i].point_list.size();
Curve3d curve = curvelist[i];
char outputfilename[300];
sprintf_s(outputfilename, 300, "D:\\CurvesOutput\\x1\\curve%d.off", i);
//定制文件名
std::ofstream out(outputfilename, std::ios::out);
out << "OFF" << endl;
out << curvelist[i].length << " 0 " << "0 " << endl;
bool isfirst = true;
Point3d point_last;
for (int j = 0; j < point_num_incurve; j++)
{
int pointindex = curve.point_list[j];
Point3d point = pointlist[pointindex];
if (point.valid == 0)
{
continue;
}
out << point.x << " " << point.y << " " << point.z << endl;
}
out.close();
}
}
2、超大矩阵
vector<vector<double>> M1(a1, vector<double>(b1, 0));
建立一个a1*b1的超大矩阵,全部赋值为0,可以非常大
3、基本算法
可以参考我原来写过的算法总结,包括各种基本数据结构的使用等等
点击打开链接
相关文章推荐
- 编程常用算法 --- C/C++ 语言实现(不定期更新)
- 每对顶点间的最短路径算法时间复杂度改进C++实现
- LinuxC/C++编程基础(8) 基于条件变量实现生产者与消费者的实例
- 几种简单常用的镜头边缘检测算法(matlab实现)
- 卡尔曼滤波简介及其算法实现代码(C++/C/MATLAB)
- java实现的18位身份证格式验证算法-Java基础-Java-编程开发
- C/C++笔试题-主要考察C/C++语言基础概念、算法及编程
- LinuxC/C++编程基础(1) 函数指针实现复数的加减乘除
- C/C++笔试题-主要考察C/C++语言基础概念、算法及编程,附参考答案,分享给大家
- LinuxC/C++编程基础(37) Cumulus::BinaryReader的实现
- 卡尔曼滤波简介及其算法实现代码(C++/C/MATLAB)
- LinuxC/C++编程基础(5) 排序二叉树的实现
- LinuxC/C++编程基础(10) quicksort的简单实现
- 常用算法的C++实现
- 常用数据结构2——栈,实现PUSH、POP和取最小值操作算法时间复杂度为o(1)
- LinuxC/C++编程基础(6) 堆排序的实现
- LinuxC/C++编程基础(19) 不可复制类的原理及实现
- c++基础8:常用的数据结构及算法
- matlab基础编程(1)-----二维数组中不同的统计算法
- 几种简单常用的镜头边缘检测算法(matlab实现)