【发布时间】:2021-01-14 07:02:23
【问题描述】:
我正在尝试使用 C 接口初始化 gnuplot,遵循 this 示例:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
void plot(float xValues[], float yValues[], int NUM_POINTS) {
char* commandsForGnuplot[] = { "set title \"TITLEEEEE\"", "plot 'data.temp'", "fflush(gnuplotPipe)" };
FILE* temp = fopen("data.temp", "w");
FILE* gnuplotPipe = _popen("gnuplot -persistent", "w");
int i;
for (i = 0; i < NUM_POINTS; i++)
{
fprintf(temp, "%lf %lf \n", xValues[i], yValues[i]); //Write the data to a temporary file
}
fclose(temp);
for (i = 0; i < 3; i++)
{
fprintf(gnuplotPipe, "%s \n", commandsForGnuplot[i]); //Send commands to gnuplot one by one.
}
}
void main(){
float a[] = {0, 1, 2, 5, 8};
float b[] = {0, 1, 2, 3, 4};
plot(a, b, 5);
}
由于某种原因,情节没有出现。我应该更正什么?
编辑
发现提示窗口显示如下信息:
"'gnuplot' 未被识别为内部或外部命令, 可运行的程序或批处理文件。”
编辑2 以下@theozh添加了gnuplot.exe的路径并解决了问题
【问题讨论】:
-
在使用 gnuplot 之前,您可以尝试关闭
temp文件 -
@Damien,已做出更正。查看更新...
-
将
gnuplot.exe的路径添加到Windows 环境变量PATH或在_popen()命令中提供gnuplot.exe的完整路径。 -
在使用之前,您应该始终检查任何
FILE *变量的NULL值。