c# - 从 .csv 文件中读取以在 c# 中查找 x,y 坐标数据集的所有峰和谷
问题描述
我需要从 csv 文件中的数据中返回所有的峰和谷。当我运行程序告诉我字符串格式不正确时,我不断收到异常。我不知道我写错了什么。我将值传递给 testX 和 testY,然后在我的 while 循环中比较它们。当我将 testY 转换为双精度时,while 循环是我得到错误的地方。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApp6
{
public partial class Form1 : Form
{
double firstY = 0.0;
string testX;
string testY;
string[] xpoint = new string[5000];
string[] ypoint = new string[5000];
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (var reader = new StreamReader(@"D:\data.csv"))
{
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
var values = line.Split(',');
testX = values[0];
testY = values[1];
while (Convert.ToDouble(testY) <= firstY)
{
firstY = Convert.ToDouble(testY);
if (firstY == Convert.ToDouble(testY))
{
break;
}
}
if (Convert.ToDouble(testY) > firstY)
{
listBox1.Items.Add(Convert.ToDouble(testX) + "," + firstY);
}
while (Convert.ToDouble(testY) >= firstY)
{
firstY = Convert.ToDouble(testY);
if (firstY == Convert.ToDouble(testY))
{
break;
}
}
if (Convert.ToDouble(testY) < firstY)
{
listBox2.Items.Add(Convert.ToDouble(testX) + "," + firstY);
}
Convert.ToString(testX);
Convert.ToString(testY);
}
}
}
}
}
解决方案
推荐阅读
- python - 如何在两个不同的字典中显示具有值的键?
- java - 如何在 c++ 和 java 之间通过 udp 有效发送数据数组
- sparql - SPARQL 查找具有相同最大值的所有元组
- sap - 用于提取足球比赛结果以自动插入数据库的工具/API
- python - 如何使用具有不同输入形状的批次制作神经网络
- c++ - C++。候选模板被忽略 - 无法将数组类型与自身匹配
- python - 仅在 Python 中某些行之后打印行
- c# - 错误:“传入”没有重载匹配委托“SerialDataReceivedEventHandler”
- python - 如何根据键合并两个字典但在python中包含缺少的键值?
- assembly - 为什么用 int 13h 读取扇区后 int 10h 不起作用?