public void SwapLog(string filename)
        {
            if (!ServiceTools.CheckIfDirectoryExists(filename))
            {
                return;
            }

            ServiceTools.logToTextFile(filename, textBox1.Text, false);

            ThreadSafeOperations.SetTextTB(textBox1, "", false);
        }
Exemplo n.º 2
0
        public bool SaveHistDataToASCII(string filename)
        {
            List <PointD> dataToSave = new List <PointD>();
            string        strToSave  = "bin-center;density" + Environment.NewLine;

            for (int i = 0; i < binsCount - 1; i++)
            {
                dataToSave.Add(new PointD(dvbinsCenters[i], dvProbDens[i]));
                strToSave += dvbinsCenters[i].ToString("e") + ";" + dvProbDens[i].ToString("e") + Environment.NewLine;
            }

            try
            {
                ServiceTools.logToTextFile(filename, strToSave);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
        public void SaveAsPDF(string filename = "", bool absolutePath = true)
        {
            if (filename == "")
            {
                return;
            }

            int pointsCount = 101;

            string matlabScript = "clear;" + Environment.NewLine;

            matlabScript += "fig = figure;" + Environment.NewLine;
            matlabScript += "set(fig,'units','normalized','outerposition',[0 0 1 1]);" + Environment.NewLine;
            matlabScript += "hold on;" + Environment.NewLine;

            double xSpaceDiff = (xSpaceMax - xSpaceMin) / (double)(pointsCount - 1);


            if (theRepresentingFunctions.Count > 0)
            {
                DenseVector xSpaceML = DenseVector.Create(pointsCount, new Func <int, double>(i =>
                {
                    return(xSpaceMin + ((double)i / (double)pointsCount) * (xSpaceMax - xSpaceMin));
                }));

                foreach (Tuple <int, double> tuple in xSpaceML.EnumerateIndexed())
                {
                    matlabScript += "xSpace(" + (tuple.Item1 + 1).ToString() + ") = " + tuple.Item2.ToString("e").Replace(",", ".") + ";" + Environment.NewLine;
                }

                int funcCounter = 0;
                for (int funcIndex = 0; funcIndex < theRepresentingFunctions.Count; funcIndex++)
                {
                    Func <DenseVector, double, double> function = theRepresentingFunctions[funcIndex];
                    DenseVector parametersVector = parameters[funcIndex];

                    DenseVector dvCurrFuncValues = DenseVector.Create(pointsCount,
                                                                      new Func <int, double>(i => function(parametersVector, xSpaceML[i])));
                    foreach (Tuple <int, double> tuple in dvCurrFuncValues.EnumerateIndexed())
                    {
                        matlabScript += "func" + funcIndex.ToString() + "(" + (tuple.Item1 + 1).ToString() + ") = " + tuple.Item2.ToString("e").Replace(",", ".") + ";" + Environment.NewLine;
                    }
                }


                for (int i = 0; i < theRepresentingFunctions.Count; i++)
                {
                    Bgr    CurrColor = lineColors[i];
                    string colR      = (CurrColor.Red / 255.0d).ToString("e").Replace(",", ".");
                    string colG      = (CurrColor.Green / 255.0d).ToString("e").Replace(",", ".");
                    string colB      = (CurrColor.Blue / 255.0d).ToString("e").Replace(",", ".");
                    matlabScript += "plot(xSpace, func" + i + ", 'Color', [" + colR + " " + colG + " " + colB + "], 'LineWidth', 2.0);" + Environment.NewLine;
                }
            }


            if ((dvScatterXSpace != null) && (dvScatterFuncValues != null))
            {
                foreach (Tuple <int, double> tuple in dvScatterXSpace.EnumerateIndexed())
                {
                    matlabScript += "scatterXSpace(" + (tuple.Item1 + 1).ToString() + ") = " + tuple.Item2.ToString("e").Replace(",", ".") + ";" + Environment.NewLine;
                }


                foreach (Tuple <int, double> tuple in dvScatterFuncValues.EnumerateIndexed())
                {
                    matlabScript += "scatterFuncVals(" + (tuple.Item1 + 1).ToString() + ") = " + tuple.Item2.ToString("e").Replace(",", ".") + ";" + Environment.NewLine;
                }

                matlabScript += "scatter(scatterXSpace, scatterFuncVals, 'bo', 'LineWidth', 2);" + Environment.NewLine;
            }

            matlabScript += "title('" + currentDescription + "', 'FontWeight','bold', 'FontUnits', 'normalized', 'FontSize', 0.03);" + Environment.NewLine;
            matlabScript += "ylabel(gca, '" + yAxisNote + "', 'FontWeight','bold', 'FontUnits', 'normalized', 'FontSize', 0.03);" + Environment.NewLine;
            matlabScript += "xlabel(gca, '" + xAxisNote + "', 'FontWeight','bold', 'FontUnits', 'normalized', 'FontSize', 0.03);" + Environment.NewLine;
            matlabScript += "export_fig '" + filename + "';" + Environment.NewLine;
            matlabScript += "close(fig);" + Environment.NewLine;

            ServiceTools.logToTextFile(filename.Replace(".", "") + ".m", matlabScript);

            //MLApp.MLApp ml = new MLApp.MLApp();
            //ml.Visible = 0;
            //ml.Execute("run('" + curDir + "tmpMLscript.m" + "');");
            //File.Delete(curDir + "tmpMLscript.m");
            //ml.Execute("exit;");
        }
Exemplo n.º 4
0
 public static bool SaveDataToCSV(this DenseVector dv, string fileName)
 {
     ServiceTools.logToTextFile(fileName, ServiceTools.densevectorToString(dv));
     return(true);
 }