Exemplo n.º 1
0
 //要素の追加
 public void Add(RowData rowData)
 {
     Datas.Add(rowData);
 }
Exemplo n.º 2
0
        //データのインポート
        private void ChooseDataFile_Click(object sender, RoutedEventArgs e)
        {
            //OpenFileDialogの作成
              var openFileDialog = new OpenFileDialog();

              openFileDialog.FilterIndex = 1;
              //CSVをフィルタ
              openFileDialog.Filter = Properties.Resources.FilterText;

              //結果を取得
              bool? result = openFileDialog.ShowDialog();
              if (result == true) {
            //ファイルを開く
            string fileName = openFileDialog.FileName;
            //ファイル名の設定
            fileNameBox.Text = fileName;
            //ボタンを有効に
            showDatasMenuItem.IsEnabled = true;
            showDatasButton.IsEnabled = true;
            learnSVMButton.IsEnabled = true;

            using (Stream fileStream = openFileDialog.OpenFile()) {
              rowDataList.Clear();
              StreamReader sr = new StreamReader(fileStream, true);

              //読み込み
              while (!sr.EndOfStream) {
            var line = sr.ReadLine();
            var values = line.Split(SEPARATOR);

            var rowData = new RowData();

            for (int i = 0; i < values.Length; i++) {
              switch (i) {
                case 0:
                  rowData.Name = values[i];
                  break;
                case 1:
                  rowData.Class = values[i];
                  break;
                case 2:
                  rowData.X = double.Parse(values[i]);
                  break;
                case 3:
                  rowData.Y = double.Parse(values[i]);
                  break;
              }
            }

            //リストに追加
            rowDataList.Add(rowData);
              }
            }
              }
        }