コード例 #1
0
    /// <summary>
    /// Generalised eigenvalues of A and B (analog to MATLAB M = eig(A,B))
    /// </summary>
    /// <param name="B">Matrix B</param>
    /// <returns>Generalised eigenvalues</returns>
    public Complex[] eige(Matrix B)
    {
        //calling Matlab API
        Eig testob = new Eig();

        //Matlab Array which gets result of Matlab function eig(A,B)
        res = testob.Eigenvalues(2, (MWNumericArray)this.matrix, (MWNumericArray)B.matrix, this.Rows());
        //arrays for real and imaginary parts
        real = (MWNumericArray)res[0];
        imag = (MWNumericArray)res[1];
        //copying parts into CSharp arrays
        double[,] resCR = (double[, ])real.ToArray(MWArrayComponent.Real);
        double[,] resCI = (double[, ])imag.ToArray(MWArrayComponent.Real);

        this.eigenvalues = new Complex[21];
        Complex[] eigenbuf = new Complex[this.rows];

        for (int i = 0; i < this.rows; i++)
        {
            eigenbuf[i] = new Complex(resCR[i, 0], resCI[i, 0]);
            eigenbuf[i] = eigenbuf[i].Pow(0.5);
        }

        Complex buf = new Complex();

        buf.quickSort(ref eigenbuf, 0, this.rows - 1);

        for (int i = 0; i < 21; i++)
        {
            this.eigenvalues[i] = eigenbuf[200 + i - 1];
        }
        return(this.eigenvalues);
    }
コード例 #2
0
        draw drawtest = new draw();//创建类 draw 的实例


        private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog d = new OpenFileDialog();

            d.Filter = "(*.mat)|*.mat|所有文件(*.*)|*.*"; if (d.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = File.OpenRead(d.FileName); StreamReader sr = new StreamReader(fs); string s;
                string     filename = d.FileName;
                d1 = pcl.loaddata(filename);
                // MessageBox.Show(filename);
                MWArray[] agrsIn = new MWArray[] { d1 };  
                pcl.pces(4, ref agrsOut, agrsIn);

                MWNumericArray x1 = agrsOut[0] as MWNumericArray;
                MWNumericArray x2 = agrsOut[1] as MWNumericArray;
                MWNumericArray x3 = agrsOut[2] as MWNumericArray;
                MWNumericArray x4 = agrsOut[3] as MWNumericArray;
                rbegin        = (double[, ])x1.ToArray();
                pend          = (double[, ])x2.ToArray();
                rpk           = (double[, ])x3.ToArray();
                f1            = (double[, ])d1.ToArray();
                qt_mean       = x4.ToScalarDouble();
                textBox4.Text = qt_mean.ToString();
                for (int i = 0; i < 12000; i++)
                {
                    data[i].X = (int)i;//强制类型转换,将double转为int,可能会丢失数据
                    data[i].Y = (int)((1000 - f1[0, i *5]) * 250 / 4500 + 100);
                }
                this.timer1.Enabled  = true; //可以使用
                this.timer1.Interval = 100;  //定时时间为100毫秒
                this.timer1.Tick    += new System.EventHandler(this.timer1_Tick);

                this.timer1.Start();//启动定时器
            }
        }
コード例 #3
0
ファイル: SparseMatrix.cs プロジェクト: hunsteve/RLResearch
        public SparseMatrix(MWNumericArray matlabArray)
        {
            double[,] data = (double[,])matlabArray.ToArray(MWArrayComponent.Real);
            int n = data.GetLength(0);

            values = new Dictionary<long, double>();
            rowElements = new HashSet<int>[n];
            columnElements = new HashSet<int>[n];

            size = n;

            for (int i = 0; i < n; ++i)
            {
                rowElements[i] = new HashSet<int>();
                columnElements[i] = new HashSet<int>();
            }

            for (int row = 0; row < n; ++row)
            {
                for (int col = 0; col < n; ++col)
                {
                    if (data[row, col] != 0) this[row, col] = (double)data[row, col];
                }
            }
        }
        /// <summary>
        /// 对波磨的移动有效值进行转换
        /// </summary>
        /// <param name="resultArray"></param>
        /// <returns></returns>
        public List <double[]> GetCalcCorrugationRms(MWNumericArray resultArray)
        {
            Array array  = resultArray.ToArray();
            int   length = array.Length / 3;

            double[] dmile  = new double[length];
            double[] dvalue = new double[length];//有效值
            double[] dspeed = new double[length];

            double[,] dArray = (double[, ])array;

            for (int i = 0; i < length; i++)
            {
                dmile[i]  = dArray[i, 0];
                dvalue[i] = dArray[i, 1];
                dspeed[i] = dArray[i, 2];
            }

            List <double[]> list = new List <double[]>();

            list.Add(dmile);
            list.Add(dvalue);
            list.Add(dspeed);

            return(list);
        }
        /// <summary>
        /// 提取焊接接头信息 返回结果集合
        /// </summary>
        /// <param name="resultArray"></param>
        /// <returns></returns>
        public List <double[]> GetWeldInfomation(MWNumericArray resultArray)
        {
            Array array  = resultArray.ToArray();
            int   length = array.Length / 5;

            double[] dmile     = new double[length];  //焊接接头处的里程
            double[] dspeed    = new double[length];  //焊接接头处的速度
            double[] drms      = new double[length];  //焊接接头处的有效值
            double[] dpeak     = new double[length];  //焊接接头处的冲击指数
            double[] dsampleNo = new double[length];  //焊接接头处的采样编号

            double[,] dArray = (double[, ])array;

            for (int i = 0; i < length; i++)
            {
                dmile[i]     = dArray[i, 0];
                dspeed[i]    = dArray[i, 1];
                drms[i]      = dArray[i, 2];
                dpeak[i]     = dArray[i, 3];
                dsampleNo[i] = dArray[i, 4];
            }

            List <double[]> list = new List <double[]>();

            list.Add(dmile);
            list.Add(dspeed);
            list.Add(drms);
            list.Add(dpeak);
            list.Add(dsampleNo);

            return(list);
        }
コード例 #6
0
        public Form1()
        {
            InitializeComponent();

            //create Object from your dll
            mymatrix.Class1 MyObject = new mymatrix.Class1();

            //run the method which gets the data and save in a MWArray object
            MWArray MatlabData = MyObject.mymatrix();

            //cast the data to MWNumericArray
            MWNumericArray TableValuesMat = (MWNumericArray)MatlabData;

            // now cast to a double array
            double[,] TableValues = (double[, ])TableValuesMat.ToArray();

            // now convert 2d array to a table in gridview:
            int height = TableValues.GetLength(0);
            int width  = TableValues.GetLength(1);

            this.dataGridView1.ColumnCount = width;
            for (int r = 0; r < height; r++)
            {
                DataGridViewRow row = new DataGridViewRow();
                row.CreateCells(this.dataGridView1);

                for (int c = 0; c < width; c++)
                {
                    row.Cells[c].Value = TableValues[r, c];
                }

                this.dataGridView1.Rows.Add(row);
            }
        }
        public List <double[]> GetCalcCorrugationAvg(MWNumericArray resultArray)
        {
            Array array  = resultArray.ToArray();
            int   length = array.Length / 3;

            double[] davgSpeed = new double[length];
            double[] davgValue = new double[length];//有效值
            double[] dsample   = new double[length];

            double[,] dArray = (double[, ])array;

            for (int i = 0; i < length; i++)
            {
                davgSpeed[i] = dArray[i, 0];
                davgValue[i] = dArray[i, 1];
                dsample[i]   = dArray[i, 2];
            }

            List <double[]> list = new List <double[]>();

            list.Add(davgSpeed); //平均速度
            list.Add(davgValue); //平均波磨有效值
            list.Add(dsample);   //求平均值的样本点的个数

            return(list);
        }
        public List <double[]> GetCorrugationWave(MWNumericArray resultArray)
        {
            Array array  = resultArray.ToArray();
            int   length = array.Length / 12;

            double[] dStartMile           = new double[length];
            double[] dEndMile             = new double[length];
            double[] dRmsValue            = new double[length];
            double[] dPeakValue           = new double[length];
            double[] dAvgSpeed            = new double[length];
            double[] dFirstBasicFrequency = new double[length];
            double[] dWaveLength          = new double[length];
            double[] dEnergyRatio         = new double[length];

            double[] dlength      = new double[length];
            double[] dchanneldata = new double[length];
            double[] dmile        = new double[length];
            double[] ddatalength  = new double[length];

            double[,] dArray = (double[, ])array;

            for (int i = 0; i < length; i++)
            {
                dStartMile[i]           = dArray[i, 0];
                dEndMile[i]             = dArray[i, 1];
                dRmsValue[i]            = dArray[i, 2];
                dPeakValue[i]           = dArray[i, 3];
                dAvgSpeed[i]            = dArray[i, 4];
                dFirstBasicFrequency[i] = dArray[i, 5];
                dWaveLength[i]          = dArray[i, 6];
                dEnergyRatio[i]         = dArray[i, 7];

                dlength[i]      = dArray[i, 8];
                dchanneldata[i] = dArray[i, 9];
                dmile[i]        = dArray[i, 10];
                ddatalength[i]  = dArray[i, 11];
            }

            List <double[]> list = new List <double[]>();

            list.Add(dStartMile);
            list.Add(dEndMile);
            list.Add(dRmsValue);
            list.Add(dPeakValue);
            list.Add(dAvgSpeed);
            list.Add(dFirstBasicFrequency);
            list.Add(dWaveLength);
            list.Add(dEnergyRatio);

            list.Add(dlength);
            list.Add(dchanneldata);
            list.Add(dmile);
            list.Add(ddatalength);

            return(list);
        }
        /// <summary>
        /// 计算连续多波指标,并根据其判断轨道几何不良区段
        /// </summary>
        /// <param name="channelName">中文通道名</param>
        /// <param name="tt">里程信息</param>
        /// <param name="wx">轨道几何不平顺,高低或轨向</param>
        /// <param name="wvelo">速度信息</param>
        /// <param name="wx_gauge">轨距</param>
        /// <param name="thresh_multi_wave">连续多波的个数,取位:3</param>
        /// <param name="thresh_multi_peak">连续多波峰值,取3.0</param>
        /// <returns></returns>
        public List <String> ContinousMultiWavePreprocess(String channelName, double[] tt, double[] wx, double[] wvelo, double[] wx_gauge, double thresh_multi_wave, double thresh_multi_peak)
        {
            List <String> dataStrList = new List <String>();
            String        dataStr     = null;

            try
            {
                int oneTimeLength = 1000000; //一次处理的点数

                for (int i = 0; i < tt.Length; i += oneTimeLength)
                {
                    int remain = 0;
                    int index  = (i / oneTimeLength) * oneTimeLength;
                    remain = tt.Length - oneTimeLength * (i / oneTimeLength + 1);
                    int      ThisTimeLength = remain > 0 ? oneTimeLength : (remain += oneTimeLength);
                    double[] tmp_tt         = new double[ThisTimeLength];
                    double[] tmp_wx         = new double[ThisTimeLength];
                    double[] tmp_wvelo      = new double[ThisTimeLength];
                    double[] tmp_wx_gauge   = new double[ThisTimeLength];

                    for (int j = 0; j < ThisTimeLength; j++)
                    {
                        tmp_tt[j]       = tt[index + j];
                        tmp_wx[j]       = wx[index + j];
                        tmp_wvelo[j]    = wvelo[index + j];
                        tmp_wx_gauge[j] = wx_gauge[index + j];
                    }

                    MWNumericArray d_tt                = new MWNumericArray(tmp_tt);
                    MWNumericArray d_wx                = new MWNumericArray(tmp_wx);
                    MWNumericArray d_wvelo             = new MWNumericArray(tmp_wvelo);
                    MWNumericArray d_wx_gauge          = new MWNumericArray(tmp_wx_gauge);
                    MWNumericArray d_thresh_multi_wave = new MWNumericArray(thresh_multi_wave);
                    MWNumericArray d_thresh_multi_peak = new MWNumericArray(thresh_multi_peak);

                    //调用算法
                    MWNumericArray resultArrayAB = (MWNumericArray)ppmc.sub_preprocessing_continous_multi_wave(d_tt, d_wx, d_wvelo, d_wx_gauge, d_thresh_multi_wave, d_thresh_multi_peak);
                    double[,] tmpArray = (double[, ])resultArrayAB.ToArray();

                    for (int j = 0; j < tmpArray.GetLength(0); j++)
                    {
                        tmpArray[j, 0] = tmp_tt[(long)(tmpArray[j, 0])];
                        tmpArray[j, 1] = tmp_tt[(long)(tmpArray[j, 1])];
                        dataStr        = String.Format("{0},{1},{2},{3}", channelName, tmpArray[j, 0], tmpArray[j, 1], tmpArray[j, 2]);
                        dataStrList.Add(dataStr);
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Source);
                MessageBox.Show(ex.Message);
            }

            return(dataStrList);
        }
コード例 #10
0
        public double[,] GenerateGameTable(int r, int z1, int z2, int z3, string f1, string f2, string f3)
        {
            MWNumericArray table = null;

            table = (MWNumericArray)M.GenerateGameTable(f1, f2, f3, z1, z2, z3, r);

            // Convert the magic square array to a two dimensional native double array
            double[,] nativeArray = (double[, ])table.ToArray(MWArrayComponent.Real);

            return(nativeArray);
        }
コード例 #11
0
        public double[,] ProbabilityChart2(string f1, string f2, string f3, int z1, int z2, int z3)
        {
            MWNumericArray chart = null;

            chart = (MWNumericArray)M.ProbabilityChart2(f1, f2, f3, z1, z2, z3);

            // Convert the magic square array to a two dimensional native double array
            double[,] nativeArray = (double[, ])chart.ToArray(MWArrayComponent.Real);

            return(nativeArray);
        }
コード例 #12
0
        public double[,] ProbabilityChart(string function, int min, int max)
        {
            MWNumericArray chart = null;

            chart = (MWNumericArray)M.ProbabilityChart(function, min, max);

            // Convert the magic square array to a two dimensional native double array
            double[,] nativeArray = (double[, ])chart.ToArray(MWArrayComponent.Real);

            return(nativeArray);
        }
        /// <summary>
        /// 对信号进行滤波:车体,架构采样后的滤波
        /// </summary>
        /// <param name="wx">原始信号:车体垂,车体横,架构垂,架构横</param>
        /// <param name="tt">里程</param>
        /// <param name="Fs">采样频率:2000/6</param>
        /// <param name="Freq_L">滤波下限频率</param>
        /// <param name="Freq_H">滤波上限频率</param>
        /// <returns>滤波后的信号</returns>
        public double[] Sub_filter_by_fft_and_ifft(double[] wx, double[] tt, double Fs, double Freq_L, double Freq_H)
        {
            double[] retVal = new double[wx.Length];

            List <double> retValList = new List <double>();

            try
            {
                int oneTimeLength = 1000000; //一次处理的点数

                for (int i = 0; i < tt.Length; i += oneTimeLength)
                {
                    int remain = 0;
                    int index  = (i / oneTimeLength) * oneTimeLength;
                    remain = tt.Length - oneTimeLength * (i / oneTimeLength + 1);
                    int      ThisTimeLength = remain > 0 ? oneTimeLength : (remain += oneTimeLength);
                    double[] tmp_tt         = new double[ThisTimeLength];
                    double[] tmp_wx         = new double[ThisTimeLength];


                    for (int j = 0; j < ThisTimeLength; j++)
                    {
                        tmp_tt[j] = tt[index + j];
                        tmp_wx[j] = wx[index + j];
                    }

                    MWNumericArray d_tt     = new MWNumericArray(tmp_tt);
                    MWNumericArray d_wx     = new MWNumericArray(tmp_wx);
                    MWNumericArray d_Fs     = new MWNumericArray(Fs);
                    MWNumericArray d_Frep_L = new MWNumericArray(Freq_L);
                    MWNumericArray d_Frep_H = new MWNumericArray(Freq_H);

                    //调用算法
                    MWNumericArray resultArrayAB = (MWNumericArray)accelerationCls.sub_filter_by_fft_and_ifft(d_wx, d_tt, d_Fs, d_Frep_L, d_Frep_H);
                    double[,] tmpArray = (double[, ])resultArrayAB.ToArray();

                    for (int j = 0; j < tmpArray.GetLength(1); j++)
                    {
                        //tmpArray[j, 0] = tmp_tt[(long)(tmpArray[j, 0])];
                        //tmpArray[j, 1] = tmp_tt[(long)(tmpArray[j, 1])];

                        retValList.Add(Math.Round(tmpArray[0, j], 4));
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Source);
                MessageBox.Show(ex.Message);
            }


            return(retValList.ToArray());
        }
コード例 #14
0
        public double[,] RobotBidChart(string function, int min, int max, int numofplayers, double p, double r, int steps)
        {
            MWNumericArray chart = null;

            chart = (MWNumericArray)M.RobotBidChart(function, min, max, numofplayers, p, GetZ0(function, p, r), r, steps);

            // Convert the magic square array to a two dimensional native double array
            double[,] nativeArray = (double[, ])chart.ToArray(MWArrayComponent.Real);

            return(nativeArray);
        }
コード例 #15
0
        private double[] Convert2Array1(MWNumericArray mwarray)
        {
            Array array = mwarray.ToArray(MWArrayComponent.Real);

            double[] returnData = new double[array.Length];
            long[]   index      = { 0L };
            for (int i = 0; i < returnData.Length; i++)
            {
                returnData[i] = (double)array.GetValue(index);
            }
            return(returnData);
        }
コード例 #16
0
        /// <summary>
        /// 只获取波磨的移动有效值
        /// </summary>
        /// <param name="resultArray"></param>
        /// <returns></returns>
        public double[] GetCalcCorrugationRmsValue(MWNumericArray resultArray)
        {
            Array array  = resultArray.ToArray();
            int   length = array.Length / 3;

            double[] dvalue = new double[length];//有效值

            double[,] dArray = (double[, ])array;

            for (int i = 0; i < length; i++)
            {
                dvalue[i] = dArray[i, 1];
            }
            return(dvalue);
        }
コード例 #17
0
        public double[] GetVerifyKilometerResult(MWNumericArray resultArray)
        {
            Array array = resultArray.ToArray();

            double[] data = new double[array.Length];

            double[,] dArray = (double[, ])array;

            for (int i = 0; i < array.Length; i++)
            {
                data[i] = dArray[0, i];
            }

            return(data);
        }
コード例 #18
0
        public void calculate(out string out1, out string out2)
        {
            out1 = "";
            out2 = "";
            double[] a = { 1, 2, 3, 4, 5, 6 }; //定义两个输入参数
            double[] b = { 1, 1, 1, 1, 1, 1 }; //它们是两个一维静态数组

            double[,] c = new double[3, 2];    //定义C#中接收输出参数的类型
            double[,] d = new double[3, 2];    //是两个二维数组

            //把两个输入参数都转换成中间类型,中间类型也是矩阵所以要指明维数
            //这里将两个输入参数转换为两个三行两列的矩阵
            MWNumericArray matlab_a = new MWNumericArray(3, 2, a);
            MWNumericArray matlab_b = new MWNumericArray(3, 2, b);

            //输入参数成功转化为两个MWArray元素类型
            MWArray[] agrsIn = new MWArray[] { matlab_a, matlab_b };

            //声明输出参数是两个MWArray元素类型,一定要写数量
            MWArray[] agrsOut = new MWArray[2];

            //调用matlab函数,2表示输出参数的个数,输出参数前需要加 ref 关键字
            //此例实现了两个三行两列的矩阵相加减
            m2CClass.MatrixOpera(2, ref agrsOut, agrsIn);

            //把两个输出参数转换成中间类型
            MWNumericArray net_c = agrsOut[0] as MWNumericArray; //matlab函数第一个输出参数
            MWNumericArray net_d = agrsOut[1] as MWNumericArray; //第二个输出参数

            //转换成C#中的接收参数
            c = (double[, ])net_c.ToArray();//转化为二维数组
            d = (double[, ])net_d.ToArray();
            //一定要注意最后接收参数的转化,不同类型的接收参数用的转换函数不同
            //二维数组用ToArray()函数转换
            //一维数组用ToVector(MWArrayComponent.Real)函数转换
            //单个double值用ToScalarDouble()函数转换
            //单个int值用ToScalarInteger()函数转换

            for (int i = 0; i <= 2; i++)//输出结果验证
            {
                for (int j = 0; j <= 1; j++)
                {
                    out1 += c[i, j].ToString() + " ";
                    out2 += d[i, j].ToString() + " ";
                }
            }
        }
コード例 #19
0
        private void Start_Click(object sender, EventArgs e)
        {
            try
            {
                //MWCharArray mw_func = new MWCharArray(func);//преобразование строки функции в тип MWCharArray
                n_0            = Convert.ToDouble(n.Text); //преобразоване string в double
                m_0            = Convert.ToDouble(m.Text);
                lambda_0       = Convert.ToDouble(lambda.Text);
                r1_0           = Convert.ToDouble(r1.Text);
                r2_0           = Convert.ToDouble(r2.Text);
                theta_0        = Convert.ToDouble(theta.Text);
                noise_0        = Convert.ToDouble(noise.Text);
                iteration_0    = Convert.ToDouble(iteration.Text);
                selectedMethod = methods.Text;


                if (selectedMethod == "Метод проекции градиента")
                {
                    ln_grad.Class1 obj_grad = new ln_grad.Class1(); //экземпляр класса компонента
                    res = obj_grad.ln_grad(2, lambda_0, r1_0, r2_0, n_0, m_0, theta_0, noise_0, iteration_0);
                }
                if (selectedMethod == "Метод квадратичного программирования")
                {
                    ln_quadprog.Class2 obj_quadprog = new ln_quadprog.Class2(); //экземпляр класса компонента
                    res = obj_quadprog.ln_quadprog(2, lambda_0, r1_0, r2_0, n_0, m_0, theta_0, noise_0);
                }
                if (selectedMethod == "Метод наименьших квадратов")
                {
                    ln_lsqlin.Class3 obj_lsqlin = new ln_lsqlin.Class3(); //экземпляр класса компонента
                    res = obj_lsqlin.ln_lsqlin(2, lambda_0, r1_0, r2_0, n_0, m_0, theta_0, noise_0);
                }


                descriptor             = (MWNumericArray)res[0];                                //выбор первого элемента из массива MWArray и преобразование в числовой тип MWNumericArray
                double[,] d_descriptor = (double[, ])descriptor.ToArray(MWArrayComponent.Real); //преобразование массива MWNUmericArray  к масииву типа double

                //for (int i = 0; i < d_descriptor.Length; i++)//вывод массива d_descriptor в RichBox
                //{
                //    richTextBox1.Text += i.ToString() + '\t';
                //    richTextBox1.Text += d_descriptor[i, 0].ToString("0.000") + '\n';//преобразование элеметна массива double в string
                //}
            }
            catch (Exception ex)//обработка исключения
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
コード例 #20
0
        private double[,] Convert2Array2(MWNumericArray mwarray)
        {
            Array array = mwarray.ToArray(MWArrayComponent.Real);

            double[,] returnData = new double[array.GetLength(0), array.GetLength(1)];
            long[] index = { 0L, 0L };
            for (int i = 0; i < returnData.GetLength(0); i++)
            {
                index[0] = i;
                for (int j = 0; j < returnData.GetLength(1); j++)
                {
                    index[1]         = j;
                    returnData[i, j] = (double)array.GetValue(index);
                }
            }
            return(returnData);
        }
コード例 #21
0
 public static void GetPath(int [] jobsequence, int [] emergency)
 {
     try
     {
         sequence1 = null;
         sequence2 = null;
         MWArray[] trans = new MWArray[] { swarmsize, (MWNumericArray)jobsequence, (MWNumericArray)emergency };
         Dyna.PSOUpdate(3, ref ending, trans);
         MWNumericArray x1 = ending[1] as MWNumericArray;
         MWNumericArray x2 = ending[2] as MWNumericArray;
         sequence1 = (double[, ])x1.ToArray();
         sequence2 = (double[, ])x2.ToArray();
     }
     catch (Exception str)
     {
         MessageBox.Show("Error!!" + str.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #22
0
ファイル: JominyCal.cs プロジェクト: benxuu/JominyPredict
        //static steelnet.Calculate sc = new Calculate();
        /// <summary>
        ///
        /// </summary>
        /// <param name="steeltype">"net1E0669"</param>
        /// <param name="inputdata">{ 0.3294, 1.0320, 0.2880, 0.0300, 0.1670, 0.0262, 0.0108, 0.0022 }</param>
        /// <returns></returns>
        public double[] steelcal_double(string steeltype, double[] input)
        {
            double[,] inputdata = new double[, ] {
                { input[0] }, { input[1] }, { input[2] }, { input[3] }, { input[4] }, { input[5] }, { input[6] }, { input[7] }
            };

            MWCharArray calname = steeltype;
            //double[] inputd = { 0.3294, 1.0320, 0.2880, 0.0300, 0.1670, 0.0262, 0.0108, 0.0022 };
            MWNumericArray x = (MWNumericArray)inputdata;
            MWNumericArray d = (MWNumericArray)sc.calculate(calname, x);

            //MWNumericArray x2 = (MWNumericArray)d;
            double[,] ddout = (double[, ])d.ToArray(MWArrayComponent.Real);
            double[] result = new double[ddout.GetLength(0)];//根据第一列长度生成结果数组;
            for (int i = 0; i < ddout.GetLength(0); i++)
            {
                result[i] = ddout[i, 0];
            }
            return(result);
        }
コード例 #23
0
        public List <double[]> GetCorrugationInfomation(MWNumericArray resultArray)
        {
            Array array  = resultArray.ToArray();
            int   length = array.Length / 8;

            double[] dStartMile           = new double[length];
            double[] dEndMile             = new double[length];
            double[] dRmsValue            = new double[length];
            double[] dPeakValue           = new double[length];
            double[] dAvgSpeed            = new double[length];
            double[] dFirstBasicFrequency = new double[length];
            double[] dWaveLength          = new double[length];
            double[] dEnergyRatio         = new double[length];

            double[,] dArray = (double[, ])array;

            for (int i = 0; i < length; i++)
            {
                dStartMile[i]           = dArray[i, 0];
                dEndMile[i]             = dArray[i, 1];
                dRmsValue[i]            = dArray[i, 2];
                dPeakValue[i]           = dArray[i, 3];
                dAvgSpeed[i]            = dArray[i, 4];
                dFirstBasicFrequency[i] = dArray[i, 5];
                dWaveLength[i]          = dArray[i, 6];
                dEnergyRatio[i]         = dArray[i, 7];
            }

            List <double[]> list = new List <double[]>();

            list.Add(dStartMile);           //平均速度
            list.Add(dEndMile);             //平均波磨有效值
            list.Add(dRmsValue);            //求平均值的样本点的个数
            list.Add(dPeakValue);           //平均速度
            list.Add(dAvgSpeed);            //平均波磨有效值
            list.Add(dFirstBasicFrequency); //求平均值的样本点的个数
            list.Add(dWaveLength);          //平均速度
            list.Add(dEnergyRatio);         //平均波磨有效值

            return(list);
        }
コード例 #24
0
ファイル: FormTest.cs プロジェクト: benxuu/JominyPredict
        private void button2_Click(object sender, EventArgs e)
        {
            steelnet.Calculate sc      = new Calculate();
            MWCharArray        calname = "net1E0669";

            //double[] inputd = { 0.3294, 1.0320, 0.2880, 0.0300, 0.1670, 0.0262, 0.0108, 0.00215 };
            double[,] minput = { { 0.3294 }, { 1.0320 }, { 0.2880 }, { 0.0300 }, { 0.1670 }, { 0.0262 }, { 0.0108 }, { 0.00215 } };
            // object[] a = sc.calculate(1,calname, minput);

            MWNumericArray input = (MWNumericArray)minput;
            MWArray        d     = sc.calculate(calname, input);
            MWNumericArray x2    = (MWNumericArray)d;

            double[,] dx3 = (double[, ])x2.ToArray(MWArrayComponent.Real);

            double[] result = new double[dx3.GetLength(0)];
            for (int i = 0; i < dx3.GetLength(0); i++)
            {
                result[i] = dx3[i, 0];
            }

            string ss = string.Empty;

            for (int i = 0; i < result.Count(); i++)
            {
                ss += result[i].ToString("0.000") + ",";
            }
            MessageBox.Show(ss);



            //MWCharArray calname = this.alg;
            //// double[] inputd = { 0.3294, 1.0320, 0.2880, 0.0300, 0.1670, 0.0262, 0.0108, 0.0022 };
            //MWNumericArray x = (MWNumericArray)this.input;
            //MWNumericArray d = (MWNumericArray)m.calculate(calname, x);
            ////MWArray d = sc.calculate((MWArray)calname,(MWArray)x);
            ////double[] s1 = new double[10];
            //this.output = (double[])d.ToVector(MWArrayComponent.Real);
        }
コード例 #25
0
        public List <double[]> GetProcessAbnormalDispResult(MWNumericArray resultArray)
        {
            Array array  = resultArray.ToArray();
            int   length = array.Length / 3;

            List <double[]> list = new List <double[]>();

            double[,] dArray = (double[, ])array;

            for (int j = 0; j < 3; j++)
            {
                double[] data = new double[length];
                for (int i = 0; i < length; i++)
                {
                    data[i] = dArray[i, j];
                }

                list.Add(data);
            }

            return(list);
        }
コード例 #26
0
        /// <summary>
        /// 计算波磨的区段大值
        /// </summary>
        /// <param name="mileData">里程</param>
        /// <param name="rmsData">有效值</param>
        /// <param name="speedData">速度</param>
        /// <param name="len_merge">段的长度</param>
        /// <returns>
        /// ww_rms_merge(:,1)  每段最大有效值对应的里程
        /// ww_rms_merge(:,2)  每段最大有效值对应的速度
        /// ww_rms_merge(:,3)   每段最大有效值
        ///</returns>
        public double[] CalcCorrugationMaxProcess(double[] mileData, double[] rmsData, double[] speedData, int len_merge)
        {
            MWNumericArray dataArray_rmsData = new MWNumericArray(rmsData);
            MWNumericArray len_mergeArray    = len_merge;

            MWNumericArray resultArray = (MWNumericArray)anc.sub_extract_segment_maxmium_value_for_corrugation(dataArray_rmsData, len_mergeArray);

            double[] dResultArray = new double[rmsData.Length];

            if (resultArray.IsEmpty || !resultArray.IsNumericArray)
            {
            }
            else
            {
                double[,] rmsArray = (double[, ])(resultArray.ToArray(MWArrayComponent.Real));

                for (int j = 0; j < rmsArray.GetLength(1); j++)
                {
                    dResultArray[j] = rmsArray[0, j];
                }
            }

            return(dResultArray);
        }
コード例 #27
0
        protected static Bitmap generateBitMap(MWNumericArray imageData)
        {
            Bitmap m = new Bitmap(imageData.Dimensions[1], imageData.Dimensions[0]);
            //Build up the bitmap from the MATLAB intesity data
            //MATLAB is using the default RGB color map with
            //an alpha channel of 1.0 (255), so just shove the
            //data straight in

            BitmapData bmd = m.LockBits(new Rectangle(0, 0, imageData.Dimensions[1], imageData.Dimensions[0]),
                                        System.Drawing.Imaging.ImageLockMode.ReadWrite,
                                        m.PixelFormat);

            try
            {
                byte[,,] a = (byte[, , ])imageData.ToArray(MWArrayComponent.Real);
                int pixelSize = 4;
                for (int idx = 0; idx < a.GetLength(1); idx++)
                {
                    for (int jdx = 0; jdx < a.GetLength(2); jdx++)
                    {
                        //swap x,y to account for MATLAB column/row orientation
                        Marshal.WriteByte(bmd.Scan0, (bmd.Stride * idx) + (pixelSize * jdx), a[2, idx, jdx]);
                        Marshal.WriteByte(bmd.Scan0, (bmd.Stride * idx) + (pixelSize * jdx + 1), a[1, idx, jdx]);
                        Marshal.WriteByte(bmd.Scan0, (bmd.Stride * idx) + (pixelSize * jdx + 2), a[0, idx, jdx]);
                        Marshal.WriteByte(bmd.Scan0, (bmd.Stride * idx) + (pixelSize * jdx + 3), 255);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            m.UnlockBits(bmd);

            return(m);
        }
コード例 #28
0
        /// <summary>
        /// 波形变化识别
        /// </summary>
        /// <param name="channelName">通道名称</param>
        /// <param name="mileData1">第一组里程</param>
        /// <param name="channelData1">第一组几何不平顺</param>
        /// <param name="speedData1">第一组速度</param>
        /// <param name="gaugeData1">第一组轨距</param>
        /// <param name="mileData2">第二组里程</param>
        /// <param name="channelData2">第二组几何不平顺</param>
        /// <param name="speedData2">第二组速度</param>
        /// <param name="gaugeData2">第二组轨距</param>
        public List <Result> WaveformChangeRecognition(string channelName, double[] mileData1, double[] channelData1, double[] speedData1, double[] gaugeData1, double[] mileData2, double[] channelData2, double[] speedData2, double[] gaugeData2)
        {
            List <Result> dataList = new List <Result>();

            try
            {
                int oneTimeLength = 600000; //一次处理的点数,150公里
                int len1          = Math.Min(mileData1.Length, channelData1.Length);
                int len2          = Math.Min(mileData2.Length, channelData2.Length);
                int len           = Math.Min(len1, len2);

                for (int i = 0; i < len; i += oneTimeLength)
                {
                    int remain = 0;
                    int index  = (i / oneTimeLength) * oneTimeLength;
                    remain = len - oneTimeLength * (i / oneTimeLength + 1);
                    int      ThisTimeLength = remain > 0 ? oneTimeLength : (remain += oneTimeLength);
                    double[] tmp_tt_1       = new double[ThisTimeLength];
                    double[] tmp_wx_1       = new double[ThisTimeLength];
                    double[] tmp_wvelo_1    = new double[ThisTimeLength];
                    double[] tmp_wx_gauge_1 = new double[ThisTimeLength];

                    double[] tmp_tt_2       = new double[ThisTimeLength];
                    double[] tmp_wx_2       = new double[ThisTimeLength];
                    double[] tmp_wvelo_2    = new double[ThisTimeLength];
                    double[] tmp_wx_gauge_2 = new double[ThisTimeLength];

                    for (int j = 0; j < ThisTimeLength; j++)
                    {
                        tmp_tt_1[j]       = mileData1[index + j];
                        tmp_wx_1[j]       = channelData1[index + j];
                        tmp_wvelo_1[j]    = speedData1[index + j];
                        tmp_wx_gauge_1[j] = gaugeData1[index + j];

                        tmp_tt_2[j]       = mileData2[index + j];
                        tmp_wx_2[j]       = channelData2[index + j];
                        tmp_wvelo_2[j]    = speedData2[index + j];
                        tmp_wx_gauge_2[j] = gaugeData2[index + j];
                    }

                    MWNumericArray d_tt_1       = new MWNumericArray(tmp_tt_1);
                    MWNumericArray d_wx_1       = new MWNumericArray(tmp_wx_1);
                    MWNumericArray d_wvelo_1    = new MWNumericArray(tmp_wvelo_1);
                    MWNumericArray d_wv_gauge_1 = new MWNumericArray(tmp_wx_gauge_1);

                    MWNumericArray d_tt_2       = new MWNumericArray(tmp_tt_2);
                    MWNumericArray d_wx_2       = new MWNumericArray(tmp_wx_2);
                    MWNumericArray d_wvelo_2    = new MWNumericArray(tmp_wvelo_2);
                    MWNumericArray d_wv_gauge_2 = new MWNumericArray(tmp_wx_gauge_2);

                    DataProcessAdvanceClass ppmc = new DataProcessAdvanceClass();
                    //调用算法
                    MWNumericArray resultArrayAB = (MWNumericArray)ppmc.sub_abrupt_change_detection(d_tt_1, d_wx_1, d_wvelo_1, d_wv_gauge_1, d_tt_2, d_wx_2, d_wvelo_2, d_wv_gauge_2);
                    double[,] tmpArray = (double[, ])resultArrayAB.ToArray();

                    for (int j = 0; j < tmpArray.GetLength(0); j++)
                    {
                        tmpArray[j, 0] = tmp_tt_2[(long)(tmpArray[j, 0])];
                        tmpArray[j, 1] = tmp_tt_2[(long)(tmpArray[j, 1])];
                        //dataStr = String.Format("{0},{1},{2},{3}", channelName, tmpArray[j, 0], tmpArray[j, 1], tmpArray[j, 2]);

                        Result result = new Result();
                        result.channelname = channelName;
                        result.startpos    = tmpArray[j, 0];
                        result.endpos      = tmpArray[j, 1];
                        result.absvalue    = tmpArray[j, 2];
                        dataList.Add(result);
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(dataList);
        }
コード例 #29
0
        /// <summary>
        /// 峰峰值偏差
        /// </summary>
        /// <param name="channelName">通道名称</param>
        /// <param name="milesData">里程</param>
        /// <param name="channelData">具体通道的数据</param>
        /// <param name="speedData">速度</param>
        /// <param name="gaugeData">轨距</param>
        /// <param name="thresh_gauge">峰峰值的阈值,取8.0</param>
        public List <Result> WaveformPeakDeviation(string channelName, double[] milesData, double[] channelData, double[] speedData, double[] gaugeData, double thresh_gauge = 8.0)
        {
            List <Result> dataList = new List <Result>();

            try
            {
                int oneTimeLength = 1000000; //一次处理的点数

                for (int i = 0; i < milesData.Length; i += oneTimeLength)
                {
                    int remain = 0;
                    int index  = (i / oneTimeLength) * oneTimeLength;
                    remain = milesData.Length - oneTimeLength * (i / oneTimeLength + 1);
                    int      ThisTimeLength = remain > 0 ? oneTimeLength : (remain += oneTimeLength);
                    double[] tmp_tt         = new double[ThisTimeLength];
                    double[] tmp_wx         = new double[ThisTimeLength];
                    double[] tmp_wvelo      = new double[ThisTimeLength];
                    double[] tmp_wx_gauge   = new double[ThisTimeLength];

                    for (int j = 0; j < ThisTimeLength; j++)
                    {
                        tmp_tt[j]       = milesData[index + j];
                        tmp_wx[j]       = channelData[index + j];
                        tmp_wvelo[j]    = speedData[index + j];
                        tmp_wx_gauge[j] = gaugeData[index + j];
                    }

                    MWNumericArray d_tt           = new MWNumericArray(tmp_tt);
                    MWNumericArray d_wx           = new MWNumericArray(tmp_wx);
                    MWNumericArray d_wvelo        = new MWNumericArray(tmp_wvelo);
                    MWNumericArray d_wx_gauge     = new MWNumericArray(tmp_wx_gauge);
                    MWNumericArray d_thresh_gauge = new MWNumericArray(thresh_gauge);

                    DataProcessAdvanceClass ppmc = new DataProcessAdvanceClass();
                    //调用算法
                    MWNumericArray resultArrayAB = (MWNumericArray)ppmc.sub_preprocessing_deviation_by_p2p(d_tt, d_wx, d_wvelo, d_wx_gauge, d_thresh_gauge);
                    double[,] tmpArray = (double[, ])resultArrayAB.ToArray();

                    for (int j = 0; j < tmpArray.GetLength(0); j++)
                    {
                        tmpArray[j, 0] = tmp_tt[(long)(tmpArray[j, 0])];
                        tmpArray[j, 1] = tmp_tt[(long)(tmpArray[j, 1])];
                        //dataStr = String.Format("{0},{1},{2},{3}", channelName, tmpArray[j, 0], tmpArray[j, 1], tmpArray[j, 2]);

                        Result result = new Result();
                        result.channelname = channelName;
                        result.startpos    = tmpArray[j, 0];
                        result.endpos      = tmpArray[j, 1];
                        result.absvalue    = tmpArray[j, 2];

                        dataList.Add(result);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }


            return(dataList);
        }
コード例 #30
0
        /// <summary>
        /// 计算连续多波指标,车体或是构架加速度
        /// </summary>
        /// <param name="channelName">中文通道名</param>
        /// <param name="tt">里程信息</param>
        /// <param name="wx">输入的加速度信号:构架或是车体</param>
        /// <param name="thresh_multi_wave">连续多波的个数,取位:车体垂-3,车体横-3,构架垂-3,构架横-6</param>
        /// <param name="thresh_multi_peak">连续多波峰值,车体垂-0.05,车体横-0.05,构架垂-0.25,构架横-0.8</param>
        /// <returns></returns>
        public List <MultiWave> Sub_preprocessing_continous_multi_wave_on_acc(string channelName, double[] tt, double[] wx, double thresh_multi_wave, double thresh_multi_peak)
        {
            //List<String> dataStrList = new List<String>();
            //String dataStr = null;

            List <MultiWave> dataList = new List <MultiWave>();

            try
            {
                int oneTimeLength = 1000000; //一次处理的点数

                for (int i = 0; i < tt.Length; i += oneTimeLength)
                {
                    int remain = 0;
                    int index  = (i / oneTimeLength) * oneTimeLength;
                    remain = tt.Length - oneTimeLength * (i / oneTimeLength + 1);
                    int      ThisTimeLength = remain > 0 ? oneTimeLength : (remain += oneTimeLength);
                    double[] tmp_tt         = new double[ThisTimeLength];
                    double[] tmp_wx         = new double[ThisTimeLength];
                    double[] tmp_wvelo      = new double[ThisTimeLength];
                    double[] tmp_wx_gauge   = new double[ThisTimeLength];

                    for (int j = 0; j < ThisTimeLength; j++)
                    {
                        tmp_tt[j] = tt[index + j];
                        tmp_wx[j] = wx[index + j];
                    }

                    MWNumericArray d_tt = new MWNumericArray(tmp_tt);
                    MWNumericArray d_wx = new MWNumericArray(tmp_wx);

                    MWNumericArray d_thresh_multi_wave = new MWNumericArray(thresh_multi_wave);
                    MWNumericArray d_thresh_multi_peak = new MWNumericArray(thresh_multi_peak);

                    //调用算法
                    MWNumericArray resultArrayAB = (MWNumericArray)ac.sub_preprocessing_continous_multi_wave_on_acc(d_tt, d_wx, d_thresh_multi_wave, d_thresh_multi_peak);
                    double[,] tmpArray = (double[, ])resultArrayAB.ToArray();

                    for (int j = 0; j < tmpArray.GetLength(0); j++)
                    {
                        tmpArray[j, 0] = tmp_tt[(long)(tmpArray[j, 0])];
                        tmpArray[j, 1] = tmp_tt[(long)(tmpArray[j, 1])];
                        //dataStr = String.Format("{0},{1},{2},{3}", channelName, tmpArray[j, 0], tmpArray[j, 1], tmpArray[j, 2]);
                        //dataStrList.Add(dataStr);

                        MultiWave wave = new MultiWave();
                        wave.ChannelName = channelName;
                        wave.StartPos    = (long)(tmpArray[j, 0]);
                        wave.EndPos      = (long)(tmpArray[j, 1]);
                        wave.AbsMinValue = tmpArray[j, 2];

                        wave.StartMile = GetAppointMilestone(citFilePath, wave.StartPos);
                        wave.EndMile   = GetAppointMilestone(citFilePath, wave.EndPos);


                        dataList.Add(wave);
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(dataList);
        }
コード例 #31
0
ファイル: MatlabUtils.cs プロジェクト: mrno/AHP
 public double[,] NetArrayFromMLArray(MWNumericArray matriz)
 {
     double[,] rdo = (double[,])matriz.ToArray(MWArrayComponent.Real);
     return rdo;
 }
コード例 #32
0
        /// <summary>
        /// 变化智能识别--调用matlab算法
        /// 几何不平顺目前包括左右高低,左右轨向
        /// </summary>
        /// <param name="channelName">中文通道名</param>
        /// <param name="tt_1">第1组数的里程</param>
        /// <param name="wx_1">第1组数的几何不平顺</param>
        /// <param name="wvelo_1">第1组数的速度</param>
        /// <param name="wx_gauge_1">第1组数的轨距</param>
        /// <param name="tt_2">第2组数的里程</param>
        /// <param name="wx_2">第2组数的几何不平顺</param>
        /// <param name="wvelo_2">第2组数的速度</param>
        /// <param name="wx_gauge_2">第2组数的轨距</param>
        /// <returns></returns>
        public List <String> ChangeDetectionPrcs(String channelName, double[] tt_1, double[] wx_1, double[] wvelo_1, double[] wx_gauge_1, double[] tt_2, double[] wx_2, double[] wvelo_2, double[] wx_gauge_2)
        {
            List <String> dataStrList = new List <String>();
            String        dataStr     = null;

            try
            {
                int oneTimeLength = 600000; //一次处理的点数,150公里
                int len1          = Math.Min(tt_1.Length, wx_1.Length);
                int len2          = Math.Min(tt_2.Length, wx_2.Length);
                int len           = Math.Min(len1, len2);

                for (int i = 0; i < len; i += oneTimeLength)
                {
                    int remain = 0;
                    int index  = (i / oneTimeLength) * oneTimeLength;
                    remain = len - oneTimeLength * (i / oneTimeLength + 1);
                    int      ThisTimeLength = remain > 0 ? oneTimeLength : (remain += oneTimeLength);
                    double[] tmp_tt_1       = new double[ThisTimeLength];
                    double[] tmp_wx_1       = new double[ThisTimeLength];
                    double[] tmp_wvelo_1    = new double[ThisTimeLength];
                    double[] tmp_wx_gauge_1 = new double[ThisTimeLength];

                    double[] tmp_tt_2       = new double[ThisTimeLength];
                    double[] tmp_wx_2       = new double[ThisTimeLength];
                    double[] tmp_wvelo_2    = new double[ThisTimeLength];
                    double[] tmp_wx_gauge_2 = new double[ThisTimeLength];

                    for (int j = 0; j < ThisTimeLength; j++)
                    {
                        tmp_tt_1[j]       = tt_1[index + j];
                        tmp_wx_1[j]       = wx_1[index + j];
                        tmp_wvelo_1[j]    = wvelo_1[index + j];
                        tmp_wx_gauge_1[j] = wx_gauge_1[index + j];

                        tmp_tt_2[j]       = tt_2[index + j];
                        tmp_wx_2[j]       = wx_2[index + j];
                        tmp_wvelo_2[j]    = wvelo_2[index + j];
                        tmp_wx_gauge_2[j] = wx_gauge_2[index + j];
                    }

                    MWNumericArray d_tt_1       = new MWNumericArray(tmp_tt_1);
                    MWNumericArray d_wx_1       = new MWNumericArray(tmp_wx_1);
                    MWNumericArray d_wvelo_1    = new MWNumericArray(tmp_wvelo_1);
                    MWNumericArray d_wv_gauge_1 = new MWNumericArray(tmp_wx_gauge_1);

                    MWNumericArray d_tt_2       = new MWNumericArray(tmp_tt_2);
                    MWNumericArray d_wx_2       = new MWNumericArray(tmp_wx_2);
                    MWNumericArray d_wvelo_2    = new MWNumericArray(tmp_wvelo_2);
                    MWNumericArray d_wv_gauge_2 = new MWNumericArray(tmp_wx_gauge_2);


                    //调用算法
                    MWNumericArray resultArrayAB = (MWNumericArray)ppmc.sub_abrupt_change_detection(d_tt_1, d_wx_1, d_wvelo_1, d_wv_gauge_1, d_tt_2, d_wx_2, d_wvelo_2, d_wv_gauge_2);
                    double[,] tmpArray = (double[, ])resultArrayAB.ToArray();

                    for (int j = 0; j < tmpArray.GetLength(0); j++)
                    {
                        tmpArray[j, 0] = tmp_tt_2[(long)(tmpArray[j, 0])];
                        tmpArray[j, 1] = tmp_tt_2[(long)(tmpArray[j, 1])];
                        dataStr        = String.Format("{0},{1},{2},{3}", channelName, tmpArray[j, 0], tmpArray[j, 1], tmpArray[j, 2]);
                        dataStrList.Add(dataStr);
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Source);
                MessageBox.Show(ex.Message);
            }

            return(dataStrList);
        }