如何用C程序绘制数据? [英] How to plot data by c program?

查看:67
本文介绍了如何用C程序绘制数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一位机械工程师,只对C编程有有限的了解.我编写了一些代码以进行仿真,并且我想可视化仿真结果.目前,我正在使用Dev-C编写代码.使用fopenfprintf命令,我生成一个包含结果的.dat文件.然后打开GNUPLOT程序并导入我的.dat文件以绘制结果.这需要时间,我必须等到模拟结束.有没有一种简便的方法可以将绘图仪与Dev-C连接,以便绘图仪在仿真过程中开始绘制数据?任何图书馆等?

I am a mechanical engineer who has only limited knowledge in C programming. I wrote some code in order to make simulations, and I want to visualize the simulation results. At the moment I am using Dev-C for writing my codes. With fopen and fprintf commands I generate a .dat file which includes the results. Then I open GNUPLOT program and import my .dat file to plot the results. This takes time and I have to wait till the end of the simulation. Is there an easy way to connect my plotter with Dev-C, so my plotter starts plotting data during the simulation? Any library or etc. ?

推荐答案

既然您已经知道gnuplot,最简单的操作可能就是从程序中调用gnuplot并将数据通过管道传递给它:

Since you already know gnuplot, the simplest thing to do may be to just call gnuplot from your program and pipe the data to it:

FILE *gnuplot = popen("gnuplot", "w");
fprintf(gnuplot, "plot '-'\n");
for (i = 0; i < count; i++)
    fprintf(gnuplot, "%g %g\n", x[i], y[i]);
fprintf(gnuplot, "e\n");
fflush(gnuplot);

这篇关于如何用C程序绘制数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆