41223215 cp2023

  • Home
    • SMap
    • reveal
    • blog
  • About
  • week5
  • week6
  • week7
  • week13
  • week15
  • week16
  • C_EX
  • ANSIC
  • 期末總結
  • Brython
week15 << Previous Next >> C_EX

week16

#include <stdio.h>
 
int main() {
    FILE *gnuplotPipe = popen("gnuplot", "w");
    if (gnuplotPipe) {
        fprintf(gnuplotPipe, "set terminal png\n");
        fprintf(gnuplotPipe, "set output 'motion_plot.png'\n");
        fprintf(gnuplotPipe, "set xlabel 'Time'\n");
        fprintf(gnuplotPipe, "set ylabel 'Position / Velocity'\n");
        fprintf(gnuplotPipe, "plot 'motion_data.txt' using 1:2 with lines title 'm1 position', 'motion_data.txt' using 1:3 with lines title 'm2 position', 'motion_data.txt' using 1:4 with lines title 'm1 velocity', 'motion_data.txt' using 1:5 with lines title 'm2 velocity'\n");
        fprintf(gnuplotPipe, "exit\n");
        fflush(gnuplotPipe);
        pclose(gnuplotPipe);
    } else {
        printf("Error opening pipe to Gnuplot.\n");
    }
    return 0;
}


week15 << Previous Next >> C_EX

Copyright © All rights reserved | This template is made with by Colorlib