我想用gnuplot绘制3D绘图(x,y,z)。在文本文件中打印矩阵
为了做到这一点,我想在C++中使用fstream将文本文件写入文本文件,然后根据this post使用splot获得数据矩阵的3D图。
假设这是做到这一点的文本文件中的数据应该是这样的正确方法:
x[1] x[2] x[3]
y[1] z[1][1] z[1][2] z[1][2]
y[2] z[2][1] z[1][2] z[2][3]
y[3] z[3][1] z[3][2] z[3][3]
为了让我写了下面的代码矩阵:
fstream myfile;
myfile.open("example.txt",fstream::out);
//rows
for (int j=0; j< 3;j++)
{
myfile << x[j]<< std::endl;
}
//columns
for (int i=0; i< 3;i++)
{
myfile << y[i]<< std::endl;
}
//columns
for (int i=1; i< 3;i++)
{
//rows
for (int j=1; j< 3;j++)
{
myfile << z[i][j] << std::endl;
}
}
myfile.close();
我以这种方式在列中获取所有内容,所以问题是如何打印矩阵?
你真的需要更好的[缩进风格(https://en.wikipedia.org/wiki/Indent_style) – NathanOliver
你知道,在C++的索引从0开始? – v010dya