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

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下都能生成图像

相关推荐

  1. 使用git出现问题

    2023-12-19 17:42:02       57 阅读
  2. WindowsQt使用MSVC编译出现需要转为unicode提示

    2023-12-19 17:42:02       53 阅读
  3. windowsdocker使用

    2023-12-19 17:42:02       50 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-19 17:42:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-19 17:42:02       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-19 17:42:02       82 阅读
  4. Python语言-面向对象

    2023-12-19 17:42:02       91 阅读

热门阅读

  1. (详解)Vue自定义指令

    2023-12-19 17:42:02       65 阅读
  2. 记一次jar冲突的问题

    2023-12-19 17:42:02       62 阅读
  3. PHP解决Safari浏览器下载文件文件名称乱码的问题

    2023-12-19 17:42:02       75 阅读
  4. Zabbix“专家坐诊”第220期问答汇总

    2023-12-19 17:42:02       59 阅读
  5. moment.js使用diff方法返回NaN

    2023-12-19 17:42:02       54 阅读
  6. 自定义折线图的颜色 Python

    2023-12-19 17:42:02       54 阅读