matlab代码
2016-02-16 09:48
399 查看
以后再补充这是干嘛的,现在只是先整理下代码
Sub cnft_click()
Dim arrAllData, arrb
Range("A:F").ClearContents
arrAllData = GetStockAllData(Range("H4"))
Application.ScreenUpdating = False
On Error Resume Next
arrb = Array("日期", "开盘价", "最高价", "成交价", "最低价", "成交量")
Dim i As Long
For i = 0 To 5
Range("A1").Offset(0, i).Value = arrb(i)
Next i
For i = 0 To UBound(arrAllData)
For j = 0 To 5
Range("a2").Offset(i, j).Value = arrAllData(i, j)
Next j
Next i
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
Function GetStockAllData(ByRef StockCode As String)
On Error Resume Next
If Len(StockCode) <> 6 Then Exit Function
'判断上证还是深证
If Left(StockCode, 2) = 60 Or Left(StockCode, 2) = 58 Then
StockCode = "sh" & StockCode
ElseIf Left(StockCode, 2) = 0 Or Left(StockCode, 2) = 3 Then
StockCode = "sz" & StockCode
Else
StockCode = "sh600000"
End If
Dim iData As String
iData = Format(Month(Date), "00")
iData = iData & Format(Day(Date), "00")
iData = Year(Date) & iData
StockCode = "http://biz.finance.sina.com.cn/stock/flash_hq/kline_data.php?symbol=" & StockCode
StockCode = StockCode & Chr(38) & "end_date=" & iData
StockCode = StockCode & Chr(38) & "begin_date=20080101"
'开始读取XML内容
Dim XML, objNode, objAtr As Object
Dim nCntChd, nCntAtr As Long
Set XML = CreateObject("Microsoft.XMLDOM")
With XML
.async = False
.Load (StockCode)
End With
Set objNode = XML.documentElement
nCntChd = objNode.ChildNodes.Length - 1 'XML的记录个数
Dim arrA
ReDim arrA(0 To nCntChd, 0 To 6)
'开始遍历
For i = 0 To nCntChd
Set objAtr = objNode.ChildNodes.Item(i)
nCntAtr = objAtr.Attributes.Length - 1
For j = 0 To nCntAtr '遍历一条记录里面的所有的记录项,记录是从0开始的
arrA(i, j) = objAtr.Attributes.Item(j).Text
Next j
Next i
Set objAtr = Nothing
Set objNode = Nothing
Set XML = Nothing
If Err.Number > 0 Then MsgBox ("查不到股票信息")
Err.Clear
On Error GoTo 0
GetStockAllData = arrA
End Function
Sub cnft_click()
Dim arrAllData, arrb
Range("A:F").ClearContents
arrAllData = GetStockAllData(Range("H4"))
Application.ScreenUpdating = False
On Error Resume Next
arrb = Array("日期", "开盘价", "最高价", "成交价", "最低价", "成交量")
Dim i As Long
For i = 0 To 5
Range("A1").Offset(0, i).Value = arrb(i)
Next i
For i = 0 To UBound(arrAllData)
For j = 0 To 5
Range("a2").Offset(i, j).Value = arrAllData(i, j)
Next j
Next i
On Error GoTo 0
Application.ScreenUpdating = True
End Sub
Function GetStockAllData(ByRef StockCode As String)
On Error Resume Next
If Len(StockCode) <> 6 Then Exit Function
'判断上证还是深证
If Left(StockCode, 2) = 60 Or Left(StockCode, 2) = 58 Then
StockCode = "sh" & StockCode
ElseIf Left(StockCode, 2) = 0 Or Left(StockCode, 2) = 3 Then
StockCode = "sz" & StockCode
Else
StockCode = "sh600000"
End If
Dim iData As String
iData = Format(Month(Date), "00")
iData = iData & Format(Day(Date), "00")
iData = Year(Date) & iData
StockCode = "http://biz.finance.sina.com.cn/stock/flash_hq/kline_data.php?symbol=" & StockCode
StockCode = StockCode & Chr(38) & "end_date=" & iData
StockCode = StockCode & Chr(38) & "begin_date=20080101"
'开始读取XML内容
Dim XML, objNode, objAtr As Object
Dim nCntChd, nCntAtr As Long
Set XML = CreateObject("Microsoft.XMLDOM")
With XML
.async = False
.Load (StockCode)
End With
Set objNode = XML.documentElement
nCntChd = objNode.ChildNodes.Length - 1 'XML的记录个数
Dim arrA
ReDim arrA(0 To nCntChd, 0 To 6)
'开始遍历
For i = 0 To nCntChd
Set objAtr = objNode.ChildNodes.Item(i)
nCntAtr = objAtr.Attributes.Length - 1
For j = 0 To nCntAtr '遍历一条记录里面的所有的记录项,记录是从0开始的
arrA(i, j) = objAtr.Attributes.Item(j).Text
Next j
Next i
Set objAtr = Nothing
Set objNode = Nothing
Set XML = Nothing
If Err.Number > 0 Then MsgBox ("查不到股票信息")
Err.Clear
On Error GoTo 0
GetStockAllData = arrA
End Function
相关文章推荐
- 以前写的matlab代码,有部分是从txt导数据到matlab里,还有合并矩阵
- matlab 绘制pdf曲线
- matlab生成EXE
- MATLAB中存储中间数据以避免重复计算
- matlab 编程遇到的问题
- Matlab randperm 洗牌函数
- MATLAB插值方法简介
- MATLAB.NET混合编程之四~~从Matlab向C#的数据类型转化
- MATLAB.NET混合编程之三~~从C#向Matlab的数据类型转化
- 手工matlab下K-means聚类算法实现而不是调用库函数
- matlab的一点问题
- Matlab中的PDEPE求解"瞬态型"或"发展型"非线性偏微分方程组
- 用PYTHON調用MATLAB的函數
- 用Matlab计算二元域GF(2)上的不可约多项式
- Matlab中的有限域计算
- MATLAB基本命令
- 基于MATLAB与C++的混合编程
- matlab按行读文件
- Matlab 点阵四维表示
- MFCC matlab code