0
votes

I have a variable N, whose input I am taking when I run my C++ code in codeblocks. It is a random walk program and I am plotting the random walk in x-y plane. Each time I plot in gnuplot, I want that N to be fetched from codeblocks input so that I can use that N as title in gnuplot. How to do this?

1

1 Answers

0
votes

you can pipe the data to gnuplot from within the C++ code :

FILE *gnuplotPipe = popen("gnuplot -persist", "w");  // Open a pipe to gnuplot

if (gnuplotPipe) {   // If gnuplot is found

...  here follow the gnuplot commands written in the pipe with fprintf()

 fflush(gnuplotPipe); //flush pipe

  fprintf(gnuplotPipe,"exit \n");   // exit gnuplot
  pclose(gnuplotPipe);    //close pipe
}

see C++ Gnuplot pipe input from C++ defined variables

or alternatively you can store the data of N in a file and plot with gnuplot from file i.e. plot 'data.dat' with linespoints ls 1

( http://www.gnuplotting.org/plotting-data/ )