private void SaveAsButton_Click(object sender, EventArgs e) { Readjust(); if (TFadjustedZ == null) { MessageBox.Show(this, "Cannot save an adjusted TF while in an error state.", "Error saving", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Matlab MAT (*.mat)|*.mat|All Files (*.*)|*.*"; sfd.FileName = Path.GetFileNameWithoutExtension(TFFilename) + "_adj.mat"; if (sfd.ShowDialog() != DialogResult.OK) { return; } var Z = CreateMatrix.DenseOfColumns(new IEnumerable <double>[] { TFadjustedZ }); //var Sr = CreateMatrix.DenseOfColumnVectors(new Vector<Complex>[] { TFadjustedSr }); var Sr = CreateMatrix.DenseOfColumns(new Vector <Complex>[] { TFadjustedSr }); var matrices = new List <MatlabMatrix>(); matrices.Add(MatlabWriter.Pack(Z, "z")); matrices.Add(MatlabWriter.Pack(Sr, "Sr")); MatlabWriter.Store(sfd.FileName, matrices); }
public void SaveToFile(string fileName) { // add simulation date and time // add simulation configuration // add add initial state of plane var matrices = new List <MatlabMatrix> { MatlabWriter.Pack(mb.DenseOfRowVectors(position_record), "position_record"), MatlabWriter.Pack(mb.DenseOfRowMajor(Vk_record.Count, 1, Vk_record), "Vk_record"), MatlabWriter.Pack(mb.DenseOfRowMajor(phi_record.Count, 1, phi_record), "phi_record"), MatlabWriter.Pack(mb.DenseOfRowMajor(psi_record.Count, 1, psi_record), "psi_record"), MatlabWriter.Pack(mb.DenseOfRowMajor(theta_record.Count, 1, theta_record), "theta_record"), MatlabWriter.Pack(mb.DenseOfRowMajor(current_T_record.Count, 1, current_T_record), "current_T_record"), MatlabWriter.Pack(mb.DenseOfRowMajor(time_record.Count, 1, time_record), "time_record"), }; MatlabWriter.Store(fileName, matrices); }
public void MatlabMatrixRoundtrip() { var denseDouble = Matrix <double> .Build.Random(20, 20); var denseComplex = Matrix <Complex> .Build.Random(10, 10); var diagonalDouble = Matrix <double> .Build.DiagonalOfDiagonalArray(new[] { 1.0, 2.0, 3.0 }); var sparseDouble = Matrix <double> .Build.Sparse(20, 20, (i, j) => i % (j + 1) == 2?i + 10 *j : 0); var denseDoubleP = MatlabWriter.Pack(denseDouble, "denseDouble"); var denseComplexP = MatlabWriter.Pack(denseComplex, "denseComplex"); var diagonalDoubleP = MatlabWriter.Pack(diagonalDouble, "diagonalDouble"); var sparseDoubleP = MatlabWriter.Pack(sparseDouble, "sparseDouble"); Assert.That(MatlabReader.Unpack <double>(denseDoubleP).Equals(denseDouble)); Assert.That(MatlabReader.Unpack <Complex>(denseComplexP).Equals(denseComplex)); Assert.That(MatlabReader.Unpack <double>(diagonalDoubleP).Equals(diagonalDouble)); Assert.That(MatlabReader.Unpack <double>(sparseDoubleP).Equals(sparseDouble)); Assert.That(MatlabReader.Unpack <double>(denseDoubleP).Storage, Is.TypeOf <DenseColumnMajorMatrixStorage <double> >()); Assert.That(MatlabReader.Unpack <Complex>(denseComplexP).Storage, Is.TypeOf <DenseColumnMajorMatrixStorage <Complex> >()); Assert.That(MatlabReader.Unpack <double>(diagonalDoubleP).Storage, Is.TypeOf <SparseCompressedRowMatrixStorage <double> >()); Assert.That(MatlabReader.Unpack <double>(sparseDoubleP).Storage, Is.TypeOf <SparseCompressedRowMatrixStorage <double> >()); if (File.Exists("testrt.mat")) { File.Delete("testrt.mat"); } MatlabWriter.Store("testrt.mat", new[] { denseDoubleP, denseComplexP, diagonalDoubleP, sparseDoubleP }); Assert.That(MatlabReader.Read <double>("testrt.mat", "denseDouble").Equals(denseDouble)); Assert.That(MatlabReader.Read <Complex>("testrt.mat", "denseComplex").Equals(denseComplex)); Assert.That(MatlabReader.Read <double>("testrt.mat", "diagonalDouble").Equals(diagonalDouble)); Assert.That(MatlabReader.Read <double>("testrt.mat", "sparseDouble").Equals(sparseDouble)); Assert.That(MatlabReader.Read <double>("testrt.mat", "denseDouble").Storage, Is.TypeOf <DenseColumnMajorMatrixStorage <double> >()); Assert.That(MatlabReader.Read <Complex>("testrt.mat", "denseComplex").Storage, Is.TypeOf <DenseColumnMajorMatrixStorage <Complex> >()); Assert.That(MatlabReader.Read <double>("testrt.mat", "diagonalDouble").Storage, Is.TypeOf <SparseCompressedRowMatrixStorage <double> >()); Assert.That(MatlabReader.Read <double>("testrt.mat", "sparseDouble").Storage, Is.TypeOf <SparseCompressedRowMatrixStorage <double> >()); File.Delete("testrt.mat"); }
protected void SaveScaledTF(double scaleFactor) { var TFSrScaled = TFSr.Divide(scaleFactor); SaveFileDialog sfd = new SaveFileDialog(); //sfd.InitialDirectory = @"C:\Users\ConraN01\Documents\Spyder_WS\MRI_RF_TF_Tool_Project\Test Files for Python Utility\Raw Neuro Header Voltage Data Files"; sfd.Filter = "MAT (*.mat)|*.mat|All Files (*.*)|*.*"; sfd.Title = "Select output scaled Etan file..."; if (sfd.ShowDialog() != DialogResult.OK) { return; } var Z = CreateMatrix.DenseOfColumns(new IEnumerable <double>[] { TFz }); var Sr = CreateMatrix.DenseOfColumnVectors(new Vector <Complex>[] { TFSrScaled }); var matrices = new List <MatlabMatrix>(); matrices.Add(MatlabWriter.Pack(Z, "z")); matrices.Add(MatlabWriter.Pack(Sr, "Sr")); MatlabWriter.Store(sfd.FileName, matrices); }