问题描述
我正在尝试使用 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,3,4};
plot(a,b,5);
}
由于某种原因,情节没有出现。我应该纠正什么?
编辑
"'gnuplot' 不被识别为内部或外部命令, 可运行的程序或批处理文件。”
编辑 2 关注@theozh添加了gnuplot.exe的路径,问题解决
解决方法
根据SO“规则”,我的评论再次作为答案:评论中没有答案。否则这个问题将继续没有答案。
要么
- 将
gnuplot.exe
的路径添加到Windows环境变量PATH
或
- 在您的
gnuplot.exe
命令中提供_popen()
的完整路径