-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImport.cs
57 lines (38 loc) · 1.5 KB
/
Import.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
namespace Mathe.Matrizenrechnung {
class Import {
public static Matrix[] StringToMatrix(string file) {
string[] strA = System.IO.File.ReadAllLines(file);
int numLines = 0;
foreach (string str in strA) {
if (str.Contains('[') && str.Contains(']')) {
numLines++;
}
}
Matrix[] matrizen = new Matrix[numLines];
int z = 0;
foreach (string str in strA) {
if (str.Contains('[') && str.Contains(']')) {
string tSub = str.Substring(str.IndexOf('[') + 1);
tSub = tSub.Remove(tSub.IndexOf(']'));
string[] tSplitD1 = tSub.Split(';');
int dim1 = tSplitD1.Length;
for (int i = 0; i < dim1; i++) {
tSplitD1[i] = tSplitD1[i].Trim();
}
int dim2 = tSplitD1[0].Split(' ').Length;
double[,] matrix = new double[dim1, dim2];
for (int i = 0; i < dim1; i++) {
string[] strs = tSplitD1[i].Split();
for (int j = 0; j < dim2; j++) {
matrix[i, j] = Convert.ToDouble(strs[j]);
}
}
matrizen[z] = new Matrix(matrix);
z++;
}
}
return matrizen;
}
}
}