Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using PCI8616card;
  2. using System;
  3. using System.Windows.Forms;
  4.  
  5. public class Util
  6. {
  7.     public static double[] average(double[,] data)
  8.     {
  9.         int len = data.GetLength(0);
  10.         int lines = data.Length/len;
  11.         double[] result = new double[len];
  12.         for(int i = 0; i < lines; i++)
  13.         {
  14.             for(int j = 0; j < len; j++)
  15.             {
  16.                 result[j] += data[i, j];
  17.             }
  18.         }
  19.         for (int j = 0; j < len; j++)
  20.         {
  21.             result[j] /= lines;
  22.         }
  23.         return result;
  24.     }
  25.  
  26.     public static void writeData(double[] data, int skipSamples)
  27.     {
  28.         SaveFileDialog saveFileDialog = new SaveFileDialog();
  29.         saveFileDialog.Title = "name of file to save";
  30.         saveFileDialog.Filter = "文本文件(*.txt)|数据文件(*.dat)";
  31.         saveFileDialog.FilterIndex = 1;
  32.         saveFileDialog.OverwritePrompt = true;
  33.         if (saveFileDialog.ShowDialog() == DialogResult.OK)
  34.         {
  35.             //获得文件路径
  36.             string filePath = saveFileDialog.FileName.ToString();
  37.             System.IO.StreamWriter objFile = new System.IO.StreamWriter(filePath);
  38.             int len = data.GetLength(0);
  39.             for (int j = skipSamples-1; j < len; j++)
  40.             {
  41.                 objFile.WriteLine(Convert.ToString(data[j]));
  42.             }
  43.             objFile.Close();
  44.             objFile.Dispose();
  45.             MessageBox.Show("保存成功!");
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement