我有三个大型矩阵,我已经转换为列向量,我试图将它们导出到csv文件。我的代码如下所示:
#include <iostream>
#include <fstream>
#include <complex>
#include <cmath>
using namespace std;
const int MAXITERS = 225;
struct Complex {
double real;
double imag;
};
void input() {
Complex c1;
c1.real = 0;
c1.imag = 0;
Complex c2;
c2.real = 0;
c2.imag = 0;
ifstream fin;
fin.open("mandelinput.txt");
fin >> c1.real >> c1.imag >> c2.real >> c2.imag;
}
double loc1(double i, Complex c1, Complex c2) {
double r1 = c1.real - c2.real;
return i * (r1 / 512) + c1.real;
}
double loc2(double j, Complex c1, Complex c2) {
double r2 = c1.imag - c2.imag;
return j * (r2 / 512) + c1.imag;
}
int mandelbrot(double x,double y) {
Complex z;
int i = 0;
z.real = 0.0;
z.imag = 0.0;
while (i<MAXITERS && z.real * z.real + z.imag * z.imag < 4) {
double zt = z.real * z.real - z.imag * z.imag + x;
z.imag = 2 * z.real * z.imag + y;
z.real = zt;
++i;
}
return i;
}
int main() {
ofstream fout;
int i,j,m;
double x = 0;
double y = 0;
Complex c1;
c1.real = 1;
c1.imag = 1;
Complex c2;
c2.real = 1;
c2.imag = 1;
input();
Complex z;
z.real = 1;
z.imag = 1;
fout.open("mandeloutput.ppm");
fout << "P3\n";
fout << "512" << " " << "512" << endl;
fout << "255\n";
for (j = 0; j < 512; j++) {
for (i = 0; i < 512; i++) {
x = loc1(i,c1,c2);
y = loc2(j,c1,c2);
m = mandelbrot(x,y);
int r = (m % 255);
int g = (m % 255);
int b = (m % 255);
fout << r << " " << g << " " << b << " ";
}
fout << endl;
}
fout.close();
}
由于某种原因,我似乎无法将此数据框写入表中。我尝试过常用方法:
zi1994 <- as.matrix(read.csv("zi 1994.csv"), header=FALSE)
xi1994 <- as.matrix(read.csv("xi 1994.csv"), header=FALSE)
yi1994 <- as.matrix(read.csv("yi 1994.csv"), header=FALSE)
vectorzi <- as.vector(zi1994)
vectorxi <- as.vector(xi1994)
vectoryi <- as.vector(yi1994)
data.frame(vectorxi, vectoryi, vectorzi)
Cod1994 <- data.frame
和
write.table(Cod1994, file = "C:/Path/Cod1994.csv")
我总是收到错误
&#34;不能强迫课程&#39;功能&#39;进入data.frame。&#34;
无论是使用write.csv(Cod1994, file = "C:/Path/Cod1994.csv")
还是<-
,都会发生这种情况。但数据框看起来很好。发生了什么事?
答案 0 :(得分:0)
要回答您的具体问题,您所做的就是让Cod1994等同于'data.frame'这个功能。你想要的是这个:
<?php
$db = new PDO('mysql:host=HOST;dbname=;charset=utf8', 'USER', 'PASS');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
?>