Guest User

Untitled

a guest
Apr 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace WindowsFormsApp6
  13. {
  14. public partial class Form1 : Form
  15. {
  16. double firstX, firstY, secondX, secondY, thirdX, thirdY, rw, cl = 0.0;
  17.  
  18. int count = 0;
  19.  
  20. string x = "";
  21. string y = "";
  22.  
  23. byte MinMax = 0; //0 equals rising, 1 equals falling
  24.  
  25. //double Max = new Array[];
  26. //double Min = new Array[];
  27.  
  28. private void button2_Click(object sender, EventArgs e)
  29. {
  30. Application.Exit();
  31. }
  32.  
  33. public Form1()
  34. {
  35. InitializeComponent();
  36. }
  37.  
  38. private void button1_Click(object sender, EventArgs e)
  39. {
  40. using (var reader = new StreamReader(@"D:data.csv"))
  41. {
  42. List<string> listA = new List<string>();
  43. List<string> listB = new List<string>();
  44. //List<int> peakIndexes;
  45. //List<int> valleyIndexes;
  46.  
  47. while (!reader.EndOfStream)
  48. {
  49.  
  50. var line = reader.ReadLine();
  51. var values = line.Split(',');
  52.  
  53. listA.Add(values[0]); //contains all the x coords
  54. listB.Add(values[1]); //contains all the y coords
  55.  
  56. //peakIndexes = new List<int>();
  57. //valleyIndexes = new List<int>();
  58.  
  59. //string[] xPoints = listA.ToArray();
  60. //string[] yPoints = listB.ToArray();
  61.  
  62. //listBox1.Items.Add(values[0]);
  63. //listBox2.Items.Add(values[1]);
  64. }
  65. }
  66. }
  67.  
  68. public void GetValleysAndPeaks(double[] yValues, out List<int> peakIndexes, out List<int> valleyIndexes)
  69. {
  70. peakIndexes = new List<int>();
  71. valleyIndexes = new List<int>();
  72.  
  73. bool directionUp = yValues[0] <= yValues[1];
  74. for (int i = 1; i < yValues.Length - 1; i++)
  75. {
  76. if (directionUp && yValues[i + 1] < yValues[i])
  77. {
  78. peakIndexes.Add(i);
  79. directionUp = false;
  80. }
  81. else if (!directionUp && yValues[i + 1] > yValues[i])
  82. {
  83. valleyIndexes.Add(i);
  84. directionUp = true;
  85. }
  86. }
  87. }
  88. }
  89. }
Add Comment
Please, Sign In to add comment