void LineGraph(vector<double> &vector_1, vector<double> &vector_2, vector<double> &vector_3, string title_) { //EXCEL DRIVER PART long N = vector_1.size(); //long M = 30; //NumericMatrix<double, long> matrix(N+1, M+1); Vector<double, long> xarr(N); Vector<double, long> yarr1(N); Vector<double, long> yarr2(N); Vector<double, long> yarr3(N); //cout << "Min" << Zarr.MinIndex() << "Max" << Zarr.MaxIndex() << "Size" <<Zarr.Size() << endl; double h1 = 1.0; xarr[xarr.MinIndex()] = 1.0; for (long j = xarr.MinIndex() + 1; j <= xarr.MaxIndex(); j++) { xarr[j] = xarr[j - 1] + h1; } yarr1[yarr1.MinIndex()] = vector_1[0]; yarr2[yarr2.MinIndex()] = vector_2[0]; yarr3[yarr3.MinIndex()] = vector_3[0]; for (long j = yarr1.MinIndex() + 1; j <= yarr1.MaxIndex(); j++) { yarr1[j] = vector_1[j - 1]; yarr2[j] = vector_2[j - 1]; yarr3[j] = vector_3[j - 1]; } //new part list<std::string> ylables = { "Beat_CAAR", "Meet_CAAR", "Miss_CAAR" }; list<Vector<double, long> > ylist = { yarr1, yarr2, yarr3 }; list<std::string> rowlabels = convertToString(xarr); list<std::string> columnlabels = convertToString(yarr1); std::string sheetName("CAAR Line Graph"); ExcelDriver& excel = ExcelDriver::Instance(); excel.MakeVisible(true); // Default is INVISIBLE! //excel.AddMatrix(sheetName, matrix, rowlabels, columnlabels); try { // Difference of vectors //printDifferenceInExcel(xarr, yarr2, yarr); printInExcel(xarr, ylables, ylist, title_); } catch (DatasimException& e) { e.print(); } catch (...) { // Catches everything else } getchar(); }
int main() { // DON'T FORGET TO MODIFY EXCELIMPORTS.CPP for correct version of Excel. long N = 40; // Create abscissa x array Vector<double, long> x(N,0.0); double T = 10.0; double h = T/double(N); x[x.MinIndex()] = 0.0; x[x.MaxIndex()] = T; for (long j = x.MinIndex()+1; j <= x.MaxIndex()-1; ++j) { x[j] = x[j-1] + h; } Vector<double, long> vec1(N,0.0); for (long j = vec1.MinIndex(); j <= vec1.MaxIndex(); ++j) { vec1[j] = pow(-1.0, j); } Vector<double, long> vec2 = vec1 + 2.0; Vector<double, long> vec3 = vec1 - 3.0; Vector<double, long> vec4 = vec1 + vec3; // Now Excel output in one sheet for comparison purpposes std::list<std::string> labels; // Names of each vector std::list<Vector<double, long > > functionResult; // The list of Y values labels.push_back("Array One"); labels.push_back("Array Two"); labels.push_back("Array Three"); labels.push_back("Array Four"); functionResult.push_back(vec1); functionResult.push_back(vec2); functionResult.push_back(vec3); functionResult.push_back(vec4); std::cout << "Data has been created\n"; try { printInExcel(x,labels, functionResult, string("All In One"), string("Time"), string("Value")); } catch(DatasimException& e) { e.print(); } return 0; }