gnuplot初探--不要使用windows下生成的数据源,的会出现未知问题

2023-12-18 16:58:06

Linux下安装gnuplot

sudo apt-get install gnuplot

安装完成后终端打印gnuplot 有下面打印即可

?生成数据的代码

#include <stdio.h>
#include <math.h>

#define ANGLE_RESOLUTION 500    // Number of angle points to calculate

int main(void)
{
   int numElements = 4;         // Number of array elements
   double spacing = 0.2;        // Element separation in metres
   double freq = 1000.0;        // Signal frequency in Hz 
   double speedSound = 343.0;   // m/s

   int a;
   int i;

   // Iterate through arrival angle points
   for (a=0 ; a<ANGLE_RESOLUTION ; a++)
   {
      // Calculate the planewave arrival angle
      double angle = -90 + 180.0 * a / (ANGLE_RESOLUTION-1);
      double angleRad = M_PI * (double) angle / 180;

      double realSum = 0;
      double imagSum = 0;

      // Iterate through array elements
      for (i=0 ; i<numElements ; i++)
      {
         // Calculate element position and wavefront delay
         double position = i * spacing;
         double delay = position * sin(angleRad) / speedSound;

         // Add Wave
         realSum += cos(2.0 * M_PI * freq * delay);
         imagSum += sin(2.0 * M_PI * freq * delay);
      }

      double output = sqrt(realSum * realSum + imagSum * imagSum) / numElements;
      double logOutput = 20 * log10(output);
      if (logOutput < -50) logOutput = -50;
      printf("%d %f %f %f %f\n", a, angle, angleRad, output, logOutput);
   }

   return 0;
}

?编译代码

gcc -o beamPattern beamPattern.c -lm

?生成数据到文件

./beamPattern > beamPattern.dat

?绘图代码 beamPattern.gnuplot

reset
unset key
set xlabel "Arrival Angle (degrees)" font "arial,12"
set ylabel "Gain (dB)" font "arial,12"
set grid lc rgbcolor "#BBBBBB"
plot 'beamPattern.dat' u 2:5 w l

?绘图完成

注意:使用windows下的数据源去linux下执行也会报这个错误

"beamPattern.gnuplot", line 6: x range is invalid

使用linux下编译生成的数据源就没这个问题 在linux和window下都能生成图像

文章来源:https://blog.csdn.net/weixin_41012767/article/details/135063802
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。