使用system()与Gnuplot进行绘图会导致错误:文件不可读
using system() to plot with Gnuplot causes error: unreadable file
我试图通过system()在gnu图中显示我的数据。我在文件中写入一些示例值,然后尝试用gnuplot显示它们。
这就是我编写测试数据的方式:
void Dataset::writeDataSetToFile(){
QString filename="/Users/rogerwilco/Desktop/test/data.txt";
QFile file(filename);
if(file.open(QIODevice::WriteOnly))
{
QTextStream stream (&file);
stream << "1" << endl << "9" << endl << "15"<< endl;
}
file.close();
}
然后在主窗口中,我触发将数据写入文件,并调用Gnuplot显示图形:
void MainWindow::saveDataToFile(){
myData->writeDataSetToFile();
}
void MainWindow::showGraph() {
system("/usr/local/bin/gnuplot '/Users/rogerwilco/Desktop/test/plotter'");
}
我收到这个错误消息:
"/Users/rogerwilco/Desktop/test/plotter",第22行:警告:跳过不可读的文件"data.txt"/Users/rogerwilco/Desktop/test/ploter",第二十二行:绘图中没有数据
gnuplot的脚本如下:
reset
n=100 #number of intervals
max=100.0 #max value
min=0.0 #min value
width=(max-min)/n #interval width
#function used to map a value to the intervals
hist(x,width)=width*floor(x/width)+width/2.0
#set term png #output terminal and file
set output "histogram.png"
set xrange [min:max]
set yrange [0:]
#to put an empty boundary around the
#data inside an autoscaled graph.
set offset graph 0.05,0.05,0.05,0.0
set xtics min,(max-min)/5,max
set boxwidth width*0.9
set style fill solid 0.5 #fillstyle
set tics out nomirror
set xlabel "x"
set ylabel "Frequency"
#count and plot
plot "data.txt" u (hist($1,width)):(1.0) smooth freq w boxes lc rgb"green" notitle
带有错误的第22行是最后一行。然而,如果我自己使用的外壳
gnuplot 'plotter'
它是有效的。
为什么当我手动将命令输入到终端时它能工作,而当我通过system()输入命令时却不能工作?
系统:
- 问题5.3.2
- Mac OS X 10.9.5
- gnuplot 4.6.6通过自制程序
- AquaTerm 1.1.1通过自制程序clang 64位
我需要在最后一行添加整个路径:
CCD_ 1。
(应该感谢Galik和Chris Stratton让我走上了正确的道路)
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 如何在文件和行号中抛出错误
- 防止在C++中选择错误文件时提升 xml 解析器崩溃
- AMQP-CPP >处理程序中的错误文件描述符
- Xcode OSX上的C++构建失败,出现多个错误文件IO..不可用:在macOS 10.15中引入
- 为什么生成文件返回 g++: 错误: h 文件或目录 make: *** [生成文件:12: 测试] 错误 1?
- 警告:打开错误文件(/build/opencv/modules/videoio/src/cap_ffmpeg_impl.
- Ubuntu C++ 编译器错误: g++: 错误: 文件.cpp: 没有这样的文件或目录
- main.cc:5:30:致命错误:文件夹/file.h:没有这样的文件或目录
- C++ LNK2005"已定义"错误 - 文件引用自身
- C++:模拟餐饮公司计费程序-无法将错误数据输出到错误文件
- 博兰德C++链接器错误c文件包括
- Visual Studio 2015 代码覆盖率错误文件
- 使用system()与Gnuplot进行绘图会导致错误:文件不可读
- 是否存在fseek/ftell可能给出错误文件大小的情况
- g++编译错误.h文件
- c++编译错误:.o文件未找到
- 打开错误文件的错误消息
- Ndk-build输出添加符号错误.文件格式错误