我有一组数据(如"34","55","114","231","60","30","49","60","75"等100个都是用引号和逗号隔开,是一个txt文件),类似正弦波曲线,如何列出所有波峰和波谷值,非常感谢!急用!!
agui.cheng@qq.com
QQ: 448935373
vb如何计算一组数的波峰波谷
答案:2 悬赏:0 手机版
解决时间 2021-02-24 14:06
- 提问者网友:活着好累
- 2021-02-23 13:18
最佳答案
- 五星知识达人网友:山有枢
- 2021-02-23 13:38
Private Sub Command1_Click()
Open "存放txt文件的路径.txt" For Input As #1
Line Input #1, x
Dim arry() As String
Dim arrx() As Integer
arry() = Split(x, ",")
m = UBound(arry)
ReDim arrx(0 To m) As Integer
For i = 0 To UBound(arry)
arrx(i) = CInt(Mid(arry(i), 2, Len(Trim(arry(i))) - 2))
Next
For i = 0 To UBound(arrx)
If i = 0 Then
Print arrx(i)
End If
If i > 1 Then
If i = UBound(arrx) Then
Print arrx(i)
Else
If arrx(i) > arrx(i - 1) And arrx(i) > arrx(i + 1) Then
Print arrx(i)
End If
If arrx(i) < arrx(i - 1) And arrx(i) < arrx(i + 1) Then
Print arrx(i)
End If
End If
End If
Next
End Sub
Open "存放txt文件的路径.txt" For Input As #1
Line Input #1, x
Dim arry() As String
Dim arrx() As Integer
arry() = Split(x, ",")
m = UBound(arry)
ReDim arrx(0 To m) As Integer
For i = 0 To UBound(arry)
arrx(i) = CInt(Mid(arry(i), 2, Len(Trim(arry(i))) - 2))
Next
For i = 0 To UBound(arrx)
If i = 0 Then
Print arrx(i)
End If
If i > 1 Then
If i = UBound(arrx) Then
Print arrx(i)
Else
If arrx(i) > arrx(i - 1) And arrx(i) > arrx(i + 1) Then
Print arrx(i)
End If
If arrx(i) < arrx(i - 1) And arrx(i) < arrx(i + 1) Then
Print arrx(i)
End If
End If
End If
Next
End Sub
全部回答
- 1楼网友:思契十里
- 2021-02-23 13:44
我想主要是确定波峰波谷的条件。
波峰:左右相邻点的值比自己小;进一步的,左右相邻的n个点值比自己小;
波谷:左右相邻点的值比自己大;进一步的,左右相邻的n个点值比自己大;
按这个思路去设计算法就可以了。编程是小问题但代码量不小这事情俺就不做了。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯