|
| 1 | +// <copyright file="MatlabStructure.cs" company="Math.NET"> |
| 2 | +// Math.NET Numerics, part of the Math.NET Project |
| 3 | +// https://numerics.mathdotnet.com |
| 4 | +// https://github.com/mathnet/mathnet-numerics |
| 5 | +// |
| 6 | +// Copyright (c) 2009-$CURRENT_YEAR$ Math.NET |
| 7 | +// |
| 8 | +// Permission is hereby granted, free of charge, to any person |
| 9 | +// obtaining a copy of this software and associated documentation |
| 10 | +// files (the "Software"), to deal in the Software without |
| 11 | +// restriction, including without limitation the rights to use, |
| 12 | +// copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | +// copies of the Software, and to permit persons to whom the |
| 14 | +// Software is furnished to do so, subject to the following |
| 15 | +// conditions: |
| 16 | +// |
| 17 | +// The above copyright notice and this permission notice shall be |
| 18 | +// included in all copies or substantial portions of the Software. |
| 19 | +// |
| 20 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 21 | +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 22 | +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 23 | +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 24 | +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 25 | +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 26 | +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 27 | +// OTHER DEALINGS IN THE SOFTWARE. |
| 28 | +// </copyright> |
| 29 | + |
| 30 | +using MathNet.Numerics.LinearAlgebra; |
| 31 | +using OneOf; |
| 32 | +using System.Collections.Generic; |
| 33 | +using System.Text; |
| 34 | + |
| 35 | +namespace MathNet.Numerics.Data.Matlab |
| 36 | +{ |
| 37 | + public class MatlabStructure : Dictionary<string, NestedObject> |
| 38 | + { |
| 39 | + } |
| 40 | + |
| 41 | + public class MatlabCellMatrix |
| 42 | + { |
| 43 | + public NestedObject[,] Data { get; private set; } |
| 44 | + |
| 45 | + public MatlabCellMatrix(int rows, int cols) |
| 46 | + { |
| 47 | + Data = new NestedObject[rows, cols]; |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + public class MatlabCharMatrix |
| 52 | + { |
| 53 | + /// <summary> |
| 54 | + /// Typically not that relevant, for UTF32 encoding however each single char is actually 2 chars (hence the string type) |
| 55 | + /// </summary> |
| 56 | + public Encoding Encoding { get; private set; } |
| 57 | + public string[,] Data { get; private set; } |
| 58 | + |
| 59 | + public MatlabCharMatrix(int rows, int cols, Encoding encoding) |
| 60 | + { |
| 61 | + Encoding = encoding; |
| 62 | + |
| 63 | + Data = new string[rows, cols]; |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Returns each row as a single string |
| 68 | + /// </summary> |
| 69 | + /// <returns></returns> |
| 70 | + public string[] ConcatRows() |
| 71 | + { |
| 72 | + string[] result = new string[Data.GetLength(0)]; |
| 73 | + for (int col = 0; col < Data.GetLength(1); col++) |
| 74 | + { |
| 75 | + for (int row = 0; row < Data.GetLength(0); row++) |
| 76 | + |
| 77 | + { |
| 78 | + result[row] += Data[row, col]; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + return result; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + public class NestedObject : OneOfBase<MatlabStructure, MatlabCellMatrix, MatlabCharMatrix, MatlabMatrix> |
| 87 | + { |
| 88 | + public NestedObject(OneOf<MatlabStructure, MatlabCellMatrix, MatlabCharMatrix, MatlabMatrix> input) : base(input) |
| 89 | + { |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments