Exemple #1
0
        public override void Process()
        {
            Dictionary <InputPort, double[]> datas = new Dictionary <InputPort, double[]>();

            foreach (var port in InputPorts.OfType <NodeSystemLib2.FormatData1D.InputPortData1D>())
            {
                var read = port.Read();
                datas.Add(port, read.Data.Take(read.Available).ToArray());
            }

            object result = null;

            if (datas.Values.Count == 1)
            {
                _matlab.Feval(_funcHeader.Name, _funcHeader.ReturnValues.Length, out result, datas.Values.ElementAt(0));
            }
            else if (datas.Values.Count == 2)
            {
                _matlab.Feval(_funcHeader.Name, _funcHeader.ReturnValues.Length, out result, datas.Values.ElementAt(0), datas.Values.ElementAt(1));
            }

            var data = (double[, ])((object[])result)[0];

            ((NodeSystemLib2.FormatData1D.OutputPortData1D)OutputPorts.First()).Buffer.Write(data, 0, data.Length);
        }
Exemple #2
0
        public void valeurSignal(string path)
        {
            bool validResult;
            // Define the output
            object result = null;

            // Call the funtion with the path
            try
            {
                matlab.Feval("valeur_signal", 1, out result, path);
                validResult = true;
            }
            catch
            {
                validResult = false;
            }

            if (validResult)
            {
                // Display result
                object[] res = result as object[];
                // res[0] is the value

                results_.Add((double)res[0]);
                //listBox1.Items.Add((double)res[0]);
            }
            else
            {
                results_.Add(0);
                listBox1.Items.Add("valeur_signal error on file " + path);
            }
        }
Exemple #3
0
        public void readWave()
        {
            // Matlab function use to get info about wav file
            object result1 = null;

            matlab.Feval("MLWavInfo", 5, out result1, fPath);
            object[] res1 = result1 as object[];
            fs                   = Math.Round((double)res1[0], 2);
            ch                   = Math.Round((double)res1[1], 2);
            totSamp              = Math.Round((double)res1[2], 2);
            dur                  = Math.Round((double)res1[3], 2);
            bits                 = Math.Round((double)res1[4], 2);
            lbl_sf.Content       = "Sample Frequency: " + fs;
            lbl_channels.Content = "Num of channels: " + ch;
            lbl_samples.Content  = "Num of Samples: " + totSamp;
            lbl_bits.Content     = "Bits/Sample: " + bits;
            lbl_dur.Content      = "Duration: " + dur;

            //matlab function to read the amplitude
            object result = null;

            matlab.Feval("MLReadWavFile", 2, out result, fPath);
            object[] res = result as object[];
            d  = (double[, ])res[0];
            fs = (double)res[1];

            //matlab function to read the freq and fresp of the wav file
            object result2 = null;

            matlab.Feval("MLFreqResp", 2, out result2, fPath);
            object[] res2 = result2 as object[];
            fResp = (double[, ])res2[0];
            freq  = (double[, ])res2[1];
        }
Exemple #4
0
        //private List<string> DataBase_DownloadData(string selectedColumn, string conditionColumn, string condition)
        //{
        //    List<string> list = new List<string>();
        //    if (sqlCon.State == ConnectionState.Closed)
        //        sqlCon.Open();
        //    SqlCommand sqlCmd = new SqlCommand("SELECT DISTINCT " + selectedColumn + " FROM tbStudies WHERE " + conditionColumn + " like '" + condition + "'", sqlCon);
        //    try
        //    {
        //        SqlDataReader dataReader = sqlCmd.ExecuteReader();

        //        while (dataReader.Read())
        //        {
        //            string listElement = dataReader[selectedColumn].ToString();
        //            list.Add(listElement);
        //        }
        //    }

        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //    }
        //    finally
        //    {
        //        sqlCon.Close();
        //    }
        //    return list;
        // }
        private void automaticalSegmentation_Click(object sender, RoutedEventArgs e)
        {
            metaData();
            object result = null;

            matlab.Feval("automaticalSegmentation", 0, out result, matlabFunctionPath);
            object[] res = result as object[];
            Display("wyniki_segmentacji_automatycznej");
        }
Exemple #5
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            object result = null;

            // Call the MATLAB function
            matlab.Feval("IndividualKNN", 1, out result, settings, "C:\\users\\asuth\\Desktop\\pokemong.jpg");

            MessageBox.Show("DONE");
        }
Exemple #6
0
 //generates the wave information
 private void waveInformation(String fileName)
 {
     object result1 = null;
     matlab.Feval("MLWavInfo", 5, out result1, fileName);
     object[] res1 = result1 as object[];
     fs = (double)res1[0];
     ch = (double)res1[1];
     totSamp = (double)res1[2];
     dur = Math.Round((double)res1[3], 3);
     bits = (double)res1[4];
     lblUpdate();
 }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Equals(pass))
            {
                //ecg

                // Create the MATLAB instance
                MLApp.MLApp matlab = new MLApp.MLApp();

                // Change to the directory where the function is located
                matlab.Execute(@"cd C:\Users\Hp1\Desktop");

                // Define the output
                object result = null;

                // Call the MATLAB function myfunc
                matlab.Feval("chk_general", 0, out result);// show dialog of arduino
                matlab.Feval("dwt_test", 2, out result, textBox1.Text + ".txt", "C:/Users/Hp1/Desktop/ardiecg/test/" + textBox1.Text + ".txt", "C:/Users/Hp1/Desktop/ardiecg/train");
                //  int milliseconds = 5000;
                //  System.Threading.Thread.Sleep(milliseconds);
                // Display result
                object[] res = result as object[];

                // Console.WriteLine(res[0]);
                //Console.WriteLine(res[1]);
                System.Diagnostics.Debug.WriteLine(res[0]);
                System.Diagnostics.Debug.WriteLine(res[1]);
                //Console.ReadLine();
                if ((textBox1.Text + ".txt").Equals(res[0]))
                {
                    status = true;
                    this.Close();
                }
                //ecg
                else
                {
                    //  int milliseconds = 10000;
                    //  System.Threading.Thread.Sleep(milliseconds);

                    System.Threading.Thread.Sleep(5000);
                    MessageBox.Show("Signal Not Identified!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    status = false;
                }
            }
            else
            {
                //  int milliseconds = 10000;
                System.Threading.Thread.Sleep(5000);
                MessageBox.Show("Signal Not Identified!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                status = false;
            }
        }
Exemple #8
0
        private void button2_Click(object sender, EventArgs e)//修正值摁钮
        {
            string str = System.Environment.CurrentDirectory;

            MLApp.MLApp matlab = new MLApp.MLApp();
            string      comm   = "";

            matlab.Execute(@"cd " + str + "\\第二步计算");
            //matlab.Execute("");
            // Define the output
            object result = null;

            // Call the MATLAB function myfunc
            matlab.Feval("T", 1, out result);
            // matlab.Feval("myfunc", 2, out result, 3.14, 42.0, "world");

            // Display result
            object[] res = result as object[];

            ans = (double[, ])res[0];
            for (int i = 0; i < 48; i++)
            {
                textBox3.Text += "第" + (i + 1).ToString() + "组解:  " + " dx:  " + ans[i, 0].ToString() + " dy:  " + ans[i, 1].ToString() + " dz:  " + ans[i, 2].ToString() + Environment.NewLine;
            }
            //textBox3.Text = ans[1,1].ToString();
            //  ans = result;
            //  MessageBox.Show(result);
            // Console.WriteLine(res[0]);
            // Console.WriteLine(res[1]);
            // Console.ReadLine();
            // n = excel.solve1();//解第二个方程
            //for(int i=0;i<48;i++)
            //{ textBox3.Text += "第" + (i + 1).ToString() + "组解:  " + " dx:  " + n[i * 3].ToString() + " dy:  " + n[i * 3 + 1].ToString() + " dz:  " + n[i * 3 + 2].ToString()+Environment.NewLine; }
        }
Exemple #9
0
        public static double[] RecognizeSketch(string filename, out int predictedClass)
        {
            object result = null;

            predictedClass = 0;

            m_Matlab.Execute(@"cd '" + m_Pwd + "\\Data'");
            m_Matlab.Feval("predictClass", 2, out result, filename);

            object[] res = result as object[];

            if (res == null || res.Length < 2)
            {
                return(null);
            }

            //Results
            //1=class, 2=imp, 3=inh
            predictedClass = (int)((double)res[0]);
            double[] probs = new double[3];

            double[,] p = (double[, ])res[1];
            for (int i = 0; i < p.GetLength(1); i++)
            {
                probs[i] = p[0, i];
            }
            return(probs);
        }
        public void RecogniteLetter(String fileName, TextBlock textBlock)
        {
            // Define the output
            object result = null;

            // Call the MATLAB function myfunc
            _matlab.Feval("getLetterForApp", 2, out result, fileName);

            // Display result
            object[] res             = result as object[];
            string   response_letter = (String)res[0];
            int      response_error  = (int)(double)res[1];

            if (response_error == 1)
            {
                MessageBoxResult messageBlankImage = MessageBox.Show("Wybrany obraz jest pusty. Spróbuj wybrać inny.",
                                                                     "Pusty obraz",
                                                                     MessageBoxButton.OK);
            }
            else if (response_error != 0)
            {
                MessageBoxResult messageBlankImage = MessageBox.Show("Bład rozpoznawania litery.",
                                                                     "Bład",
                                                                     MessageBoxButton.OK);
            }
            else
            {
                textBlock.Text = (String)res[0];
            }
        }
Exemple #11
0
        private void MatlabAction(string sWPID, string sPathOfApp)
        {
            // Folgenden Zeilen basieren auf einem Beispiel von Matlab
            // Create the MATLAB instance

            String sFileName = System.IO.Path.GetFileName(sPathOfApp);
            String sFilePath = sPathOfApp.Replace("\\" + sFileName, "");



            Type MatlabType = Type.GetTypeFromProgID("Matlab.Desktop.Application");

            MLApp.MLApp matlab = (MLApp.MLApp)Activator.CreateInstance(MatlabType);

            // Change to the directory where the function is located
            String sExecutePath = "cd " + sFilePath;

            matlab.Execute(sExecutePath);

            // Define the output
            object result = null;

            // Call the MATLAB function myfunc
            matlab.Feval(sFileName.Replace(".m", ""), 1, out result, sWPID);

            // Display result
            object[] res = result as object[];
            // Hier könnte noch eine Abfrage folgen ob das Result ein Fehler ist !!! Ist noch nicht definiert wie das aussieht.
        }
        private void masstochargeMatlab_Range(double startXval, double endXval)
        {
            int selectedfileNumber_start = Convert.ToInt32(startXval) + 1;
            int selectedfileNumber_end   = Convert.ToInt32(endXval) + 1;
            int selectedFileNumber       = selectedfileNumber_end - selectedfileNumber_start + 1;

            if (selectedfileNumber_start > intFileNumber || selectedfileNumber_start > intFileNumber)
            {
                //not to over max Xvalue
                selectedfileNumber_start = intFileNumber;
                selectedfileNumber_end   = intFileNumber;
            }

            // Create the MATLAB instance
            MLApp.MLApp matlab = new MLApp.MLApp();
            matlab.Execute(matlab_path);

            object resultdata = null;

            //There is no xLength Data
            if (xLength == 0)
            {
                xLength = 25000;
            }

            matlab.Feval("mTcPlot_Range", 2, out resultdata, selectedfileNumber_start, selectedfileNumber_end, xLength);

            object[] res = resultdata as object[];

            object_To_double(res);
        }
Exemple #13
0
        private void reducereEBtn_Click(object sender, EventArgs e)
        {
            if (pathTB.Text.Trim() != "")
            {
                try
                {
                    MLApp.MLApp matlab = new MLApp.MLApp();
                    matlab.Execute(@"cd E:\FisiereWAV");
                    object result = null;
                    matlab.Feval("MyFunc3", 1, out result, selectedFile, "REcho-", selectedFilePath);

                    rezultatFiltrareTB.Text = "REcho-" + selectedFile;
                    soundFilter             = new SoundPlayer(@"E:\FisiereWAV\Workspace\" + "REcho-" + selectedFile);
                    soundFilter.Play();

                    pictureBox1.Visible       = true;
                    pictureBox1.ImageLocation = @"E:\FisiereWAV\Workspace\" + "REcho-" + Path.GetFileNameWithoutExtension(selectedFile) + ".jpg";
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Eroare la conexiunea cu MATLAB: " + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Nu ati ales fisierul audio!", reducereEBtn.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #14
0
        private void test_struct_pass()
        {
            object obj_struct_out;

            matlab.Feval("test_struct_out", 1, out obj_struct_out, 1, 2, 3);
            object[] res_out = obj_struct_out as object[];
            Debug.WriteLine(res_out);

            object obj_struct_in;

            matlab.Feval("test_struct_in", 3, out obj_struct_in, obj_struct_out);
            object[] res = obj_struct_in as object[];
            Debug.WriteLine(res[0]);
            Debug.WriteLine(res[1]);
            Debug.WriteLine(res[2]);
        }
        protected void EnhanceImage_Click(object sender, EventArgs e)
        {
            MLApp.MLApp matlab = new MLApp.MLApp();

            matlab.Execute("cd " + Server.MapPath(MATLAB_FUNCTIONS_FOLDER));

            object result = null;

            App_Code.Image image = App_Code.SqlUtilities.GetImage(int.Parse(Request["id"]));

            string[] temp = image.Path.Split('/');
            string imageName = temp[temp.Length - 1];

            matlab.Feval("enhance", 1, out result, Server.MapPath(image.Path), imageName, loggedUsername);

            object[] res = result as object[];

            string resultPath = "~/Images/" + loggedUsername + "/" + (string)res[0];

            System.Web.UI.WebControls.Image imageControl = (System.Web.UI.WebControls.Image)ThumbnailsHolder.Controls[1];

            imageControl.ImageUrl = resultPath;

            if (ViewState["editedImagePath"] != null)
            {
                DeleteImage(null, null);
            }
            ViewState["editedImagePath"] = resultPath;

            AddSaveDeleteButtons();
        }
        public void pulseFunction()
        {
            matlab.Execute(@"cd 'C:\Users\Anna Birgersson\Documents\MATLAB\Shimmer Matlab Instrument Driver v2.6'");//\ShimmerBiophysicalProcessingLibrary_Rev_0_10.jar");

            while (isRunning)
            {
                // Define the output
                object result = null;

                // Call the MATLAB function myfunc

                matlab.Feval("ecgtoheartrate", 1, out result, "7", 15, "testdata.dat");

                // Display result
                object[] res = result as object[];

                Console.Write("\r{0} ", res[0]);

                //TODO: Uppdaterar label och skriver pulsen
                Dispatcher.Invoke(() =>
                {
                    pulseLabel.Content = "Pulse: " + res[0];
                });

                int i;
                i = Convert.ToInt32(res[0]);
                allPulses.Add(i);                                               // add pulse to allPulse list
                timePulses.Add(Convert.ToInt32(sw.ElapsedMilliseconds) / 1000); // lista med tid
            }
        }
        private void getMatlabdata()
        {
            // Create the MATLAB instance
            MLApp.MLApp matlab = new MLApp.MLApp();
            matlab.Execute(matlab_path);

            object resultdata = null;

            matlab.Feval("binfileReader2", 2, out resultdata);

            object[] res = resultdata as object[];



            double[,] intensity = (double[, ])res[0];
            fileNumber          = (double)res[1];
            intFileNumber       = Convert.ToInt32(fileNumber);
            dintensity          = new double[intensity.Length];



            for (int i = 0; i < intensity.Length; i++)
            {
                dintensity[i] = intensity[0, i];
            }

            InitialZedGraph();
        }
        Bitmap GetBitmap(string path)
        {
            object result = null;


            // Call the MATLAB function
            matlab.Feval("ReadImage", 3, out result, path, rows, columns, gaussian);

            // Display result
            object[] res = result as object[];

            byte[,,] bs     = res[0] as byte[, , ];
            object[,] files = res[1] as object[, ];
            object[,] descs = res[2] as object[, ];

            int w = bs.GetLength(1);
            int h = bs.GetLength(0);

            //var h = bs.Length;
            //var w = bs[0].Length;

            Bitmap bmp = new Bitmap(w, h);

            for (int i = 0; i < bmp.Height; i++)
            {
                for (int j = 0; j < bmp.Width; j++)
                {
                    System.Drawing.Color c = System.Drawing.Color.FromArgb(bs[i, j, 0], bs[i, j, 1], bs[i, j, 2]);

                    bmp.SetPixel(j, i, c);
                }
            }

            for (int i = 0; i < files.GetLength(0); i++)
            {
                for (int j = 0; j < files.GetLength(1); j++)
                {
                    try
                    {
                        filenames[i, j] = files[i, j].ToString();
                    }
                    catch (Exception) { }
                }
            }

            for (int i = 0; i < descs.GetLength(0); i++)
            {
                for (int j = 0; j < descs.GetLength(1); j++)
                {
                    try
                    {
                        fileDescriptions[i, j] = descs[i, j].ToString();
                    }
                    catch (Exception) { }
                }
            }

            return(bmp);
        }
Exemple #19
0
        public void pcaVisualization(double[] Orignal, double[] Pca)
        {
            MLApp.MLApp matlb = new MLApp.MLApp();
            matlb.Execute("cd C:\\temp");
            object res = null;

            matlb.Feval("pcaVisualizeFunc", 1, out res, Orignal, Pca);
        }
Exemple #20
0
        private void runMATLAB(string s, string[] args)
        {
            MLApp.MLApp matlab       = new MLApp.MLApp();
            object      matlabResult = null;

            matlab.Execute(@"cd C:\work\temp\images\simple");
            matlab.Feval(s, 0, out matlabResult, args[0], args[1], args[2]);
        }
Exemple #21
0
        private void btn_RotateImg_Click(object sender, RoutedEventArgs e)
        {
            MLApp.MLApp matlab       = new MLApp.MLApp();
            object      matlabResult = null;


            matlab.Execute(@"cd C:\work\temp\images\simple\simple2");
            matlab.Feval("rotateImg", 0, out matlabResult, doubleUpDown1.Value);
        }
Exemple #22
0
        public void MatlabPlotPcaChart(double[][] components)
        {
            object output = null;

            MLApp.MLApp matlab = new MLApp.MLApp();
            matlab.Execute(@"cd c:\");
            //matlab.Execute(@"cd e:\Workspaces\FERI\semestar II\Neuro nano in kvantno racunalnistvo\neuro myo");
            matlab.Feval("PlotPcaChart", 0, out output, components[0], components[1], components[2]);
        }
        //private void ComputeDencities()
        //{
        //    foreach (RTPObservation obs in Observations)
        //    {
        //        if (obs.ObservationNumber != 2)
        //        {
        //            foreach (RTPState state in States)
        //            {
        //                double[] ReceptionDurationSamples = ModelSamples.Where(s => s.State == state.StateNumber && s.Observation == obs.ObservationNumber).Select(s => s.Frame.ReceptionDuration).ToArray();
        //                for (int i = 0; i < ReceptionDurationSamples.Length; i++)
        //                    if (ReceptionDurationSamples[i] < 0.0000001) ReceptionDurationSamples[i] = 0.0000001;
        //                double[] res = GammaFit(ReceptionDurationSamples);
        //                Dencities[obs.ObservationNumber, state.StateNumber] = new GammaParams(res[0], res[1]);
        //                //StateDencities.Add(GammaFit(receiveSpeedSamples));
        //            }
        //        }
        //        else
        //        {
        //            double[] ReceptionDurationSamples = ModelSamples.Where(s => s.Observation == obs.ObservationNumber).Select(s => s.Frame.ReceptionDuration).ToArray();
        //            for (int i = 0; i < ReceptionDurationSamples.Length; i++)
        //                if (ReceptionDurationSamples[i] < 0.0000001)
        //                    ReceptionDurationSamples[i] = 0.0000001;
        //            double[] res = GammaFit(ReceptionDurationSamples);
        //            foreach (RTPState state in States)
        //            {
        //                Dencities[obs.ObservationNumber, state.StateNumber] = new GammaParams(res[0], res[1]);
        //            }
        //        }
        //    }
        //}


        //        MLApp.MLApp matlab = new MLApp.MLApp();

        //// Change to the directory where the function is located
        //matlab.Execute(@"cd c:\temp\example");

        //// Define the output
        //object result = null;

        //// Call the MATLAB function myfunc
        //matlab.Feval("myfunc", 2, out result, 3.14, 42.0, "world");



        private double[] GammaFit(double[] sequence)
        {
            object gamfit_result = null;

            Matlab.Feval("gamfit", 2, out gamfit_result, sequence);
            object[] res    = gamfit_result as object[];
            double[] result = new double[2];
            result[0] = ((double[, ])res[0])[0, 0];
            result[1] = ((double[, ])res[0])[0, 1];
            return(result);

            //MWNumericArray m_seq = new MWNumericArray(sequence);
            //MWArray res = matlabFunctions.GammaFit(m_seq);
            //double[] result = new double[2];
            //result[0] = ((double)(res.ToArray().GetValue(0, 0)));
            //result[1] = ((double)(res.ToArray().GetValue(0, 1)));
            //return result;
        }
Exemple #24
0
        private void button10_Click_1(object sender, RoutedEventArgs e)
        {
            MLApp.MLApp matlab       = new MLApp.MLApp();
            object      matlabResult = null;


            matlab.Execute(@"cd C:\work\temp\images\simple\simple2");
            matlab.Feval("LineCutGUI", 0, out matlabResult);
        }
Exemple #25
0
        public void signalVisualization(double[] Orignal, double[] Pca, double[] Ica)
        {
            MLApp.MLApp matlb = new MLApp.MLApp();
            matlb.Execute("cd C:\\temp");

            object res = null;

            matlb.Feval("myfunc2", 1, out res, Orignal, Pca, Ica);
        }
Exemple #26
0
        public List <RecommendedArtist> GetRecommendationsOnGenre(User fan, List <Artist> artists, int noOfRecommendations)
        {
            List <Artist>            recommendedArtists = new List <Artist>();
            List <RecommendedArtist> recommendations    = new List <RecommendedArtist>();

            if (fan.Genres.Count == 0)
            {
                return(recommendations);
            }
            String genresTxt = "";

            using (var unitOfWork = new UnitOfWork())
            {
                var genresRepository = unitOfWork.GetRepository <Genre>();
                foreach (Genre g in genresRepository.GetAll())
                {
                    if (fan.Genres.Where(x => x.Id == g.Id).Count() != 0)
                    {
                        genresTxt += fan.Id + "," + g.Id + "," + 1 + ";";
                    }
                    else
                    {
                        genresTxt += fan.Id + "," + g.Id + "," + 0 + ";";
                    }
                }
            }

            MLApp.MLApp matlab = new MLApp.MLApp();
            matlab.Execute(@"cd C:\Users\Luiza");
            object result = null;

            // Call the MATLAB function myfunc
            matlab.Feval("genreSimilarity", 1, out result, genresTxt);

            // Display result
            object[] res = result as object[];
            object   arr = res[0];

            double[,] pairs = (double[, ])arr;
            for (int i = 0; i < pairs.Length / 2; i++)
            {
                var artist = artists.Where(a => a.User.Role == (int)RolesEnum.ARTIST && a.ArtistId == pairs[i, 0]).FirstOrDefault();
                if (artist != null && pairs[i, 1] * 100 > 10 && artist.Ratings.Where(r => r.FanId == fan.Id).Count() == 0)
                {
                    recommendations.Add(new RecommendedArtist
                    {
                        Id         = artist.ArtistId,
                        Name       = artist.User.Name,
                        Score      = pairs[i, 1] * 100,
                        PictureUrl = artist.PictureUrl,
                        Why        = "Acest artist iti este recomandat deoarece genurile tale muzicale preferate se potrivesc cu ale sale" +
                                     " in proportie de " + Math.Round(pairs[i, 1] * 100, 2) + "%."
                    });
                }
            }
            return(recommendations.Take(noOfRecommendations).ToList());
        }
        public ImageInfoMark ImageReal(string ImagePath)
        {
            ImageInfoMark info = new ImageInfoMark();
            object        output;

            object[] result;
            MatlabObj.Feval("CheckRealImage", 4, out output, ImagePath, BagPath, MeanMhistRGBPath, RealSamplePath);
            result = output as object[];

            info.Result = Convert.ToInt16(result[0]);
            if (info.Result == 1)
            {
                info.IsImgReal = true;
            }
            info.Rate        = Convert.ToDouble(result[1]);
            info.RunningTime = Convert.ToDouble(result[2]);
            info.ErrorDesc   = Convert.ToString(result[3]);
            //Console.WriteLine("CheckRealImage: \n\t Ket Qua That Gia : " + Result + "\n\t Thoi Gian Chay :" + RunningTime + "\n\t Trang Thai Loi : " + ErrorDesc);
            return(info);
        }
Exemple #28
0
        public static object PlotGraphHistory(IGraph graph, string msg = "")
        {
            var graphHistory = graph.GetEdgesHistory();

            Matlab.Execute($"cd '{_pathToPlotFunctionFolder}'");
            Matlab.Feval("plot_graph_history", 0, out var figure, graphHistory.Source.ToArray(),
                         graphHistory.Target.ToArray(), graphHistory.Weigth.ToArray(), graphHistory.Marker.ToArray(),
                         graph.Directed, msg);
            return(figure);
        }
Exemple #29
0
        private void button12_Click(object sender, RoutedEventArgs e)
        {
            MLApp.MLApp matlab = new MLApp.MLApp();
            object      result = null;

            double deltaX = (double)doubleUpDown_Matlab.Value;

            matlab.Execute(@"cd C:\work\temp\images\simple\simple2");
            matlab.Feval("verticleLineCutFeed", 0, out result, "*.jpg", deltaX);

            img_Cut_rectangle.Visibility = Visibility.Hidden;
            image2.Source = new BitmapImage(new Uri(@"C:\work\temp\images\simple\simple2\cuts.jpg", UriKind.RelativeOrAbsolute));
        }
Exemple #30
0
        public void initalize_tx_params(double M_i, double fsym_tx_i, double fs_tx_i, double fc_i)
        {
            this.M       = M_i;
            this.fsym_tx = fsym_tx_i;
            this.fs_tx   = fs_tx_i;
            this.fc      = fc_i;
            object init_out;

            matlab.Feval("initialize_NIMultiThread_MATLAB_TX", 5, out init_out, M_i, fsym_tx_i, fs_tx_i);
            object[] tx_init_obj = init_out as object[];
            this.Ts_tx  = (double)tx_init_obj[0];
            this.sps_tx = (double)tx_init_obj[1];
            block_copy((double[, ])tx_init_obj[2], out this.qammod_lookup_real);
            // this.qammod_lookup_real = (double[,])tx_init_obj[2];
            block_copy((double[, ])tx_init_obj[3], out this.qammod_lookup_imag);
            // this.qammod_lookup_imag = (double[,])tx_init_obj[3];
            block_copy((double[, ])tx_init_obj[4], out this.rc_filt_tx);
            set_aside_real = new double[1, this.rc_filt_tx.Length - 1];
            set_aside_imag = new double[1, this.rc_filt_tx.Length - 1];
            // this.rc_filt_tx = (double[,])tx_init_obj[4];
            // this.max_waveform_size = max_waveform_size;
        }
 private void proc()
 {
     MLApp.MLApp Call_Matlab = new MLApp.MLApp();
     Call_Matlab.Visible = 0;
     object result = null;
     Call_Matlab.Execute(@"cd C:\MatlabProcessing");
     try
     {
         Call_Matlab.Feval("MAIN_PROCESSING", 1, out result, PthTs, PthTr, PthAl);
         Res = result as object[];
         MessageBox.Show(Res[0].ToString());
         Call_Matlab.Quit();
         Marshal.ReleaseComObject(Call_Matlab);
     }
     catch (Exception e)
     {
         Marshal.ReleaseComObject(Call_Matlab);
         MessageBox.Show(e.ToString());
     }
 }
        public Tuple<double[], double> Execute(double l1, double l2, double l3)
        {
            MLApp.MLApp matlab = new MLApp.MLApp();

            var appFolder = Path.GetDirectoryName(
                Assembly.GetExecutingAssembly().Location
            );
            var workFolder = Path.Combine(appFolder, "Matlab");

            matlab.Execute(@"cd " + workFolder);

            object result = null;

            matlab.Feval("Calculation", 2, out result, l1, l2, l3);

            // Display result
            object[] res = (object[])result;
            var x = (double[,])res[0];
            var fval = (double)res[1];

            return Tuple.Create(new double[] { x[0, 0], x[0, 1], x[0, 2] }, fval);
        }
        static void Main(string[] args)
        {
            /////////////////////////////////////// Looking for a file  ///////////////////////////////////////
            int m = 0, n;

            //Learning the value of m(Number of training examples) and n(number of atributes)
            using (TextReader reader = File.OpenText("C:/Users/laerte/Desktop/ex1data1.txt"))
            {
                string linha = reader.ReadLine();
                string[] temp = linha.Split(',');
                n = temp.Length - 1;
                while (linha != null)
                {
                    m++;
                    linha = reader.ReadLine();
                }
                reader.Close();
            }

            double[,] X = new double[m, n + 1];
            double[,] y = new double[m, 1];
            double[,] theta = new double[n + 1, 1];

            //filling out the matrix X, the vector y, and the vector theta
            using (TextReader reader = File.OpenText("C:/Users/laerte/Desktop/ex1data1.txt"))
            {
                int i = 0;
                string linha = reader.ReadLine();
                while (linha != null)
                {
                    string[] temp = linha.Split(',');
                    X[i, 0] = 1;
                    for (int j = 1; j < n + 1; j++)
                    {
                        //Console.Write(temp[j - 1]);
                        X[i, j] = Convert.ToDouble(temp[j - 1]);
                    }
                    y[i, 0] = Convert.ToDouble(temp[n]);
                    linha = reader.ReadLine();
                    i++;
                }
                reader.Close();
            }
            for (int i = 0; i < n + 1; i++)
            {
                theta[i, 0] = 0;
            }

            /*
            ////////////////////////////////////////////// PRINT ////////////////////////////////////////////////
            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n + 1; j++)
                {
                    Console.Write("X[{0}][{1}] = {2} ", i, j, X[i, j]);
                }
                Console.Write("\n");
            }

            for (int i = 0; i < m; i++)
            {
                Console.Write("y[{0}] = {1}\n", i, y[i,0]);
            }

            for (int i = 0; i < n + 1; i++)
            {
                Console.Write("theta[{0}] = {1}\n", i, theta[i,0]);
            }
            */

            ////////////////////////////////////////////Matlab calculations/////////////////////////////////////////////

            // Create the MATLAB instance
            MLApp.MLApp matlab = new MLApp.MLApp();

            // Change to the directory where the function is located
            matlab.Execute(@"cd C:\Users\laerte\Desktop");

            // Define the output
            object result = null;

            // Call the MATLAB function myfunc
            matlab.Execute("clear all");
            matlab.Feval("computeCost", 1, out result, X, y, theta);

            // Display result
            object[] res = result as object[];

            Console.WriteLine("Computing the cost J = " + res[0]);
            // Closing the matblab window
            //matlab.Quit();
            // Wait until fisnih
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            /////////////////////////////////////// Looking for a file  ///////////////////////////////////////
            // Variables used in matlab
            //double lambda = 1.5;

            //Reading the file to get the size of lines and columns of R and Y, which will be used in training colloborative filtering
            int num_jobs_init;
            int num_users_init;
            int num_features;
            using (TextReader readerR = File.OpenText("C:/Users/larissaf/Desktop/files/Y.txt"))
            {
                num_jobs_init = 0;
                string line = readerR.ReadLine();
                string[] temp = line.Split('\t');
                num_users_init = temp.Length;
                while (line != null)
                {
                    line = readerR.ReadLine();
                    num_jobs_init++;
                }
                readerR.Close();
            }
            //it needs to be between 1 and num_users_init (PUT A VERIFICATION HERE)
            /*

            Console.Write("Write down the user number that will receive job recommendation from 1 to {0}\n", num_users_init);
            string read = Console.ReadLine();
             *
             */
            int user_number = 1;

            StreamWriter writetext = new StreamWriter("results.txt");
            string space = "\t";
            string new_line = "\n";

            while (user_number <= 100)
            {

                //Now we read R and Y from theirs files (-1 because I will remove the chosen user from the matrixes)
                double[,] Y = new double[num_jobs_init, num_users_init - 1];
                double[,] R = new double[num_jobs_init, num_users_init - 1];

                // Movie rating file for a user
                double[,] my_ratings = new double[num_jobs_init, 1];

                //reading Y_training
                using (TextReader readerY = File.OpenText("C:/Users/larissaf/Desktop/files/Y.txt"))
                {
                    int i = 0;
                    string line = readerY.ReadLine();
                    while (line != null)
                    {
                        string[] temp = line.Split('\t');
                        int k = 0;
                        for (int j = 0; j < num_users_init; j++)
                        {
                            if (j != (user_number - 1))
                            {
                                Y[i, k] = Convert.ToDouble(temp[j]);
                                k++;
                            }
                            else
                                my_ratings[i, 0] = Convert.ToDouble(temp[j]);
                        }
                        line = readerY.ReadLine();
                        i++;
                    }
                    readerY.Close();
                }
                //reading R_training
                using (TextReader readerR = File.OpenText("C:/Users/larissaf/Desktop/files/R.txt"))
                {
                    int i = 0;
                    string line = readerR.ReadLine();
                    while (line != null)
                    {
                        string[] temp = line.Split('\t');
                        int k = 0;
                        for (int j = 0; j < num_users_init; j++)
                        {
                            if (j != (user_number - 1))
                            {
                                R[i, k] = Convert.ToDouble(temp[j]);
                                k++;
                            }
                        }
                        line = readerR.ReadLine();
                        i++;
                    }
                    readerR.Close();
                }

                //reading X to get the number of features
                using (TextReader readerX = File.OpenText("C:/Users/larissaf/Desktop/files/X.txt"))
                {
                    num_features = 0;
                    string line = readerX.ReadLine();
                    if (line != null)
                    {
                        string[] temp = line.Split('\t');
                        num_features = temp.Length;
                    }
                    readerX.Close();
                }
                //allocating the X matriz
                double[,] X = new double[num_jobs_init, num_features];

                //reading X_training
                using (TextReader readerX = File.OpenText("C:/Users/larissaf/Desktop/files/X.txt"))
                {
                    int i = 0;
                    string line = readerX.ReadLine();
                    while (line != null)
                    {
                        string[] temp = line.Split('\t');
                        for (int j = 0; j < num_features; j++)
                        {
                            X[i, j] = Convert.ToDouble(temp[j]);
                        }
                        line = readerX.ReadLine();
                        i++;
                    }
                    readerX.Close();
                }

                // make sure that the data will be zero for all the positions
                using (TextReader reader_movies_ratings = File.OpenText("C:/Users/larissaf/Desktop/files/one_user_rating.txt"))
                {
                    int i = 0;
                    string line = reader_movies_ratings.ReadLine();
                    while (line != null)
                    {
                        string[] temp = line.Split('\t');
                        my_ratings[Convert.ToInt32(temp[0]) - 1, 0] = Convert.ToInt32(temp[1]);

                        line = reader_movies_ratings.ReadLine();
                        i++;
                    }
                    reader_movies_ratings.Close();
                }

                // Job names
                string[] job_list = new string[num_jobs_init];
                using (TextReader reader_movie_list = File.OpenText("C:/Users/larissaf/Desktop/files/job_names.txt"))
                {
                    string line = reader_movie_list.ReadLine();
                    int i = 0;
                    while (line != null)
                    {
                        job_list[i] = line;
                        line = reader_movie_list.ReadLine();
                        i++;
                    }
                    reader_movie_list.Close();
                }

                ////////////////////////////////////////////Matlab calculations///////////////////////////////////////////

                // Create the MATLAB instance
                MLApp.MLApp matlab = new MLApp.MLApp();

                // Change to the directory where the functions are located --- always use the desktop to make tests to avoid problems with pathway
                matlab.Execute(@"cd C:\Users\larissaf\Desktop\files");

                // Define the output to print the final result
                object result_movies_search = null;

                matlab.Execute("my_ratings");

                // Movie erecommendations script
                matlab.Feval("scriptGeneration", 6, out result_movies_search, my_ratings, job_list, Y, R, X, num_features);
                object[] res = result_movies_search as object[];

                //Console.Write("{0} {1}", res[5], job_list[(int)(((double[,])res[0])[0, 0]) - 1]);

                // ----------------------------------------------------------------------

                // writetext.Write(res[5]);
                int len = ((double[,])res[0]).Length;

                for (int i = 0; i < len; i++)
                {
                    writetext.Write(job_list[(int)(((double[,])res[0])[i, 0]) - 1]);
                    writetext.Write(space);
                    writetext.Write((((double[,])res[1])[i, 0]));
                    writetext.Write(space);
                    writetext.Write(job_list[(int)(((double[,])res[2])[i, 0]) - 1]);
                    writetext.Write(space);
                    writetext.Write((((double[,])res[3])[i, 0]));
                    writetext.Write(space);
                    writetext.Write((((double[,])res[4])[i, 0]));
                    writetext.Write(space);
                    writetext.Write(user_number);
                    writetext.Write(new_line);
                }

                user_number++;
            } // while ends
            writetext.Close();
            Console.Write(" DONE");
            // Wait until fisnih
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            //////////////////////////////////////////////////////////////////// Loading files  /////////////////////////////////////////////////////////////////////
            // Variables used in matlab
            //double lambda = 1.5;
            double num_users = 4;
            double num_movies = 5;
            double num_features = 3;

            // Generate data according with the logic express in Matlab
            double[,] X = new double[(int)num_movies, (int)num_features];
            double[,] Y = new double[(int)num_movies, (int)num_users];
            double[,] Theta = new double[(int)num_users, (int)num_features];
            double[,] R = new double[(int)num_movies, (int)num_users];

            //filling out the matrix X
            using (TextReader readerX = File.OpenText("C:/Users/laerte/Documents/GitHub/ummatlab/Recommender systems/Data/data_x.txt"))
            {
                int i = 0;
                string line = readerX.ReadLine();
                while (line != null)
                {
                    string[] temp = line.Split('\t');
                    for (int j = 0; j < (int)num_features; j++)
                    {
                        //Console.Write(temp[j - 1]);
                        X[i, j] = Convert.ToDouble(temp[j]);
                    }
                    line = readerX.ReadLine();
                    i++;
                }
                readerX.Close();
            }

            //filling out the matrix Y
            using (TextReader readerY = File.OpenText("C:/Users/laerte/Documents/GitHub/ummatlab/Recommender systems/Data/data_y.txt"))
            {
                int i = 0;
                string line = readerY.ReadLine();
                while (line != null)
                {
                    string[] temp = line.Split('\t');
                    for (int j = 0; j < (int)num_users; j++)
                    {
                        //Console.Write(temp[j - 1]);
                        Y[i, j] = Convert.ToDouble(temp[j]);
                    }
                    line = readerY.ReadLine();
                    i++;
                }
                readerY.Close();
            }

            // Filling out the matrix theta
            using (TextReader readerTheta = File.OpenText("C:/Users/laerte/Documents/GitHub/ummatlab/Recommender systems/Data/data_theta.txt"))
            {
                int i = 0;
                string line = readerTheta.ReadLine();
                while (line != null)
                {
                    string[] temp = line.Split('\t');
                    for (int j = 0; j < (int)num_features; j++)
                    {
                        //Console.Write(temp[j - 1]);
                        Theta[i, j] = Convert.ToDouble(temp[j]);
                    }
                    line = readerTheta.ReadLine();
                    i++;
                }
                readerTheta.Close();
            }

            // Filling out the matrix theta
            using (TextReader readerR = File.OpenText("C:/Users/laerte/Documents/GitHub/ummatlab/Recommender systems/Data/data_r.txt"))
            {
                int i = 0;
                string line = readerR.ReadLine();
                while (line != null)
                {
                    string[] temp = line.Split('\t');
                    for (int j = 0; j < (int)num_users; j++)
                    {
                        //Console.Write(temp[j - 1]);
                        R[i, j] = Convert.ToDouble(temp[j]);
                    }
                    line = readerR.ReadLine();
                    i++;
                }
                readerR.Close();
            }

            //Reading the file to get the size of lines and columns of R and Y, which will be used in training colloborative filtering
            int num_movies_init;
            int num_users_init;
            using (TextReader readerSize = File.OpenText("C:/Users/laerte/Desktop/Y_training.txt"))
            {
                num_movies_init = 0;
                string line = readerSize.ReadLine();
                string[] temp = line.Split('\t');
                num_users_init = temp.Length;
                while (line != null)
                {
                    line = readerSize.ReadLine();
                    num_movies_init++;
                }
                readerSize.Close();
            }
            //Now we read R and Y from theirs files
            double[,] Y_training = new double[num_movies_init, num_users_init];
            double[,] R_training = new double[num_movies_init, num_users_init];
            //reading Y_training
            using (TextReader readerY = File.OpenText("C:/Users/laerte/Desktop/Y_training.txt"))
            {
                int i = 0;
                string line = readerY.ReadLine();
                string[] temp = line.Split('\t');
                while (line != null)
                {
                    for (int j = 0; j < num_users_init; j++)
                    {
                        Y_training[i, j] = Convert.ToDouble(temp[j]);
                    }
                    line = readerY.ReadLine();
                    i++;
                }
                readerY.Close();
            }
            //reading R_training
            using (TextReader readerR = File.OpenText("C:/Users/laerte/Desktop/R_training.txt"))
            {
                int i = 0;
                string line = readerR.ReadLine();
                string[] temp = line.Split('\t');
                while (line != null)
                {
                    for (int j = 0; j < num_users_init; j++)
                    {
                        R_training[i, j] = Convert.ToDouble(temp[j]);

                    }
                    line = readerR.ReadLine();
                    i++;
                }
                readerR.Close();
            }

            // Movie rating file for a user X
            double[,] my_ratings = new double[num_movies_init, 1];
            // make sure that the data will be zero for all the other positions
            Array.Clear(my_ratings, 0, num_movies_init);
            using (TextReader reader_movies_ratings = File.OpenText("C:/Users/laerte/Documents/GitHub/ummatlab/Recommender systems/Data/movies_ratings.txt"))
            {
                int i = 0;
                string line = reader_movies_ratings.ReadLine();
                while (line != null)
                {
                    string[] temp = line.Split('\t');
                    my_ratings[Convert.ToInt32(temp[0]) - 1, 0] = Convert.ToInt32(temp[1]);

                    line = reader_movies_ratings.ReadLine();
                    i++;
                }
                reader_movies_ratings.Close();
            }

            // Movie list file for a user X
            string[] movie_list = new string[num_movies_init];
            using (TextReader reader_movie_list = File.OpenText("C:/Users/laerte/Documents/GitHub/ummatlab/Recommender systems/Data/movie_ids.txt"))
            {
                string line = reader_movie_list.ReadLine();
                int i = 0;
                while (line != null)
                {
                    line = line.Replace((i + 1).ToString() + " ", "");
                    movie_list[i] = line;
                    line = reader_movie_list.ReadLine();
                    i++;
                }
                reader_movie_list.Close();
            }

            /////////////////////////////////////////////////////////////////////// Matlab calculations /////////////////////////////////////////////////////////////////////

            // Create the MATLAB instance
            MLApp.MLApp matlab = new MLApp.MLApp();

            // Change to the directory where the functions are located --- always use the desktop to make tests to avoid problems with pathway
            matlab.Execute(@"cd C:\Users\laerte\Desktop");

            // Calling a function to calculate the parameters to send it to cofiCostFunc
            object parameters = null;
            matlab.Feval("generateParams", 1, out parameters, X, Theta);
            object[] par = parameters as object[];

            // Define the output to print the final result for CofiCostFunc
            //object result = null;

            // Call the MATLAB function myfunc
            matlab.Execute("clear all");

            // Execute the function in Matlab function to check J
               // matlab.Feval("cofiCostFunc", 2, out result, (par[0]), Y, R, num_users, num_movies, num_features, lambda);

            // Checking the gradients
            //object check = null;
            //matlab.Feval("checkCostFunction", 0, out check, lambda);

            // Display result [cost, grad] = costFunctionReg(initial_theta, X, y, lambda);
            //object[] res = result as object[];

            // Print J and grad from CofiCostFunc, which are the returned by this function  --- I will commment this part
            Console.WriteLine("Go to Matlab to do the interactions...");
            /*
            Console.WriteLine("Computing the cost J = " + res[0]);
            int len = ((double[,])(res[1])).Length;
            for (int n=0; n < len; n++)
            {
                Console.WriteLine("grad = " +((double[,])res[1])[n,0]);
            }
             */

             // Define the output to print the final result
            object result_movies_search = null;

            // Movie recommendations script
            matlab.Feval("scriptGeneration", 1, out result_movies_search, my_ratings, movie_list, Y_training, R_training);

            // Wait until fisnih
            Console.Write("Presse ENTER to close the window");
            Console.ReadLine();
            // Closing the matblab window
            //matlab.Quit();
        }
        static void Main(string[] args)
        {
            int num_jobs_init;
            int num_users_init;
            int num_features;
            int user_number = 1;

            //Reading the file to get the size of lines and columns of R and Y,
            //which will be used in training colloborative filtering.
            using (TextReader readerR = File.OpenText("C:/Users/larissaf/Desktop/files/Y.txt"))
            {
                num_jobs_init = 0;
                string line = readerR.ReadLine();
                string[] temp = line.Split('\t');
                num_users_init = temp.Length;
                while (line != null)
                {
                    line = readerR.ReadLine();
                    num_jobs_init++;
                }
                readerR.Close();
            }

            //File that is going to be written with the Top ten jobs and ratings and similarity for all users
            StreamWriter writetext = new StreamWriter("results.txt");

            //Dictionary that contains a list of top ten jobs compared with other jobs for each user
            Dictionary<int, List<MyData>> finalList = new Dictionary<int, List<MyData>>();

            //consider that we have 100 users (we can ask how may and change the while-condition)
            while (user_number <= 100)
            {
                //Now we read R and Y from theirs files (-1 because I will remove the chosen user from the matrixes)
                double[,] Y = new double[num_jobs_init, num_users_init - 1];
                double[,] R = new double[num_jobs_init, num_users_init - 1];

                // Movie rating file for a user
                double[,] my_ratings = new double[num_jobs_init, 1];

                //reading Y_training
                using (TextReader readerY = File.OpenText("C:/Users/larissaf/Desktop/files/Y.txt"))
                {
                    int i = 0;
                    string line = readerY.ReadLine();
                    while (line != null)
                    {
                        string[] temp = line.Split('\t');
                        int k = 0;
                        for (int j = 0; j < num_users_init; j++)
                        {
                            if (j != (user_number - 1))
                            {
                                Y[i, k] = Convert.ToDouble(temp[j]);
                                k++;
                            }
                            else
                                my_ratings[i, 0] = Convert.ToDouble(temp[j]);
                        }
                        line = readerY.ReadLine();
                        i++;
                    }
                    readerY.Close();
                }
                //reading R_training
                using (TextReader readerR = File.OpenText("C:/Users/larissaf/Desktop/files/R.txt"))
                {
                    int i = 0;
                    string line = readerR.ReadLine();
                    while (line != null)
                    {
                        string[] temp = line.Split('\t');
                        int k = 0;
                        for (int j = 0; j < num_users_init; j++)
                        {
                            if (j != (user_number - 1))
                            {
                                R[i, k] = Convert.ToDouble(temp[j]);
                                k++;
                            }
                        }
                        line = readerR.ReadLine();
                        i++;
                    }
                    readerR.Close();
                }

                //reading X to get the number of features
                using (TextReader readerX = File.OpenText("C:/Users/larissaf/Desktop/files/X.txt"))
                {
                    num_features = 0;
                    string line = readerX.ReadLine();
                    if (line != null)
                    {
                        string[] temp = line.Split('\t');
                        num_features = temp.Length;
                    }
                    readerX.Close();
                }

                //allocating the X matriz
                double[,] X = new double[num_jobs_init, num_features];

                //reading X_training
                using (TextReader readerX = File.OpenText("C:/Users/larissaf/Desktop/files/X.txt"))
                {
                    int i = 0;
                    string line = readerX.ReadLine();
                    while (line != null)
                    {
                        string[] temp = line.Split('\t');
                        for (int j = 0; j < num_features; j++)
                        {
                            X[i, j] = Convert.ToDouble(temp[j]);
                        }
                        line = readerX.ReadLine();
                        i++;
                    }
                    readerX.Close();
                }

                /*
                using (TextReader reader_movies_ratings = File.OpenText("C:/Users/larissaf/Desktop/files/one_user_rating.txt"))
                {
                    int i = 0;
                    string line = reader_movies_ratings.ReadLine();
                    while (line != null)
                    {
                        string[] temp = line.Split('\t');
                        my_ratings[Convert.ToInt32(temp[0]) - 1, 0] = Convert.ToInt32(temp[1]);

                        line = reader_movies_ratings.ReadLine();
                        i++;
                    }
                    reader_movies_ratings.Close();
                }*/

                // Job names
                string[] job_list = new string[num_jobs_init];
                using (TextReader reader_movie_list = File.OpenText("C:/Users/larissaf/Desktop/files/job_names.txt"))
                {
                    string line = reader_movie_list.ReadLine();
                    int i = 0;
                    while (line != null)
                    {
                        job_list[i] = line;
                        line = reader_movie_list.ReadLine();
                        i++;
                    }
                    reader_movie_list.Close();
                }

                ////////////////////////////////////////////Matlab calculations///////////////////////////////////////////

                // Create the MATLAB instance
                MLApp.MLApp matlab = new MLApp.MLApp();

                //this is used to do not show the matlab window
                //matlab.Visible = 0;

                // Change to the directory where the functions are located --- always use the desktop to make tests to avoid problems with pathway
                matlab.Execute(@"cd C:\Users\larissaf\Desktop\files");

                // Define the output to print the final result
                object result_movies_search = null;

                matlab.Execute("my_ratings");

                // Movie erecommendations script
                matlab.Feval("scriptGeneration", 6, out result_movies_search, my_ratings, job_list, Y, R, X, num_features);
                object[] res = result_movies_search as object[];

                int len = ((double[,])res[0]).Length;

                //for each one of the users, we will have a list containg all the comparassions between the top ten jobs for him, and
                //the other jobs (that had similarity >= 70%)
                List<MyData> mylist = new List<MyData>();
                MyData aux;

                for (int i = 0; i < len; i++)
                {
                    //adding a new element in the list for each user.
                    aux = new MyData(job_list[(int)(((double[,])res[0])[i, 0]) - 1], (((double[,])res[1])[i, 0]), job_list[(int)(((double[,])res[2])[i, 0]) - 1], (((double[,])res[3])[i, 0]), (((double[,])res[4])[i, 0]));
                    mylist.Add(aux);

                    writetext.Write(job_list[(int)(((double[,])res[0])[i, 0]) - 1] + "\t");
                    writetext.Write((((double[,])res[1])[i, 0]) + "\t");
                    writetext.Write(job_list[(int)(((double[,])res[2])[i, 0]) - 1] + "\t");
                    writetext.Write((((double[,])res[3])[i, 0]) + "\t");
                    writetext.Write((((double[,])res[4])[i, 0]) + "\t");
                    writetext.Write(user_number + "\n");
                }

                //adding the list at the Dictionary for each user
                finalList.Add(user_number, mylist);

                user_number++;
            } // while ends

            writetext.Close();

            //creating a instance of an object for user 1: (maybe send null)
            dataResult avgs = new dataResult(null, 10);
            avgs.WriteInAFile(finalList);

            Console.WriteLine("DONE");

            // Wait until fisnih
            Console.ReadLine();
        }