static private void UseDotNET(Array ar, Array ai, Array br,
            Array bi, ref Array cr, ref Array ci, ref Array dr, ref Array di)
        {
            /*
             * This function calls the math_by_numbers method from
             * inside a .NET assembly created with MATLAB using Builder
             * for .NET.
             */

            // Instantiate our .NET class from the MATLAB created component
            dotnetclass AClass = new dotnetclass();

            // explicity convert our input arguments into MWArrays
            // this can be done with implicit conversion
            MWNumericArray a = new MWNumericArray(1, 2, (double[])ar, (double[])ai);
            MWNumericArray b = new MWNumericArray(1, 2, (double[])br, (double[])bi);

            // call math_on_method from Assembly specifying the number
            // of return arguments expected and passing in a and b
            MWArray[] RetVal = AClass.math_on_numbers(2, a, b);

            // Unpack return values seperating the real and imaginary parts
            // using the ToArray method of MWNummericArray.  Since RetVal was
            // declared as a MWArray above, it must be explicity typecast here.  
            cr = ((MWNumericArray) RetVal[0]).ToVector(MWArrayComponent.Real);
            ci = ((MWNumericArray) RetVal[0]).ToVector(MWArrayComponent.Imaginary);
        
            dr = ((MWNumericArray) RetVal[1]).ToVector(MWArrayComponent.Real);
            di = ((MWNumericArray) RetVal[1]).ToVector(MWArrayComponent.Imaginary);

        }
        public void train()
        {
            dotnetclass AClass = new dotnetclass();

            int s_id = 1;

            while (s_id < 6)
            {
                MWNumericArray subj_id = new MWNumericArray(s_id);
                StreamReader sr = new StreamReader("ecg" + s_id + ".txt");

                while (sr.Peek() != -1)
                {
                    double[] ecg = new double[1280];
                    string line;
                    int i = 0;
                    int b = 0;
                    for (i = 0; i < 1280; i++)
                    {
                        if ((line = sr.ReadLine()) != null)
                        {
                            if (String.IsNullOrWhiteSpace(line))
                            {
                                b = 1;
                                break;
                            }
                            double line1 = Convert.ToDouble(line);
                            ecg[i] = line1;
                        }
                    }
                    if (b == 1) break;
                    MWNumericArray ecg_raw = new MWNumericArray(1280, 1, ecg);
                    MWArray RetVal = AClass.process(ecg_raw, M);

                    MWArray gal = new MWNumericArray();
                    gal = gallery;
                    gallery = AClass.addtogallery(gal, RetVal);

                    MWArray id_temp = new MWNumericArray();
                    id_temp = id;
                    id = AClass.addtoid(id_temp, subj_id);
                }
                if (sr != null) sr.Close();
                s_id++;
            }
            weights = AClass.dlda(gallery, id);
            projected_gallery = AClass.projection(gallery, weights);
        }