以下是一个示例 VBA 代码,用于构建一个纵坐标为 0-3.5,横坐标为 0-5.5,曲线弯曲上升的坐标系数据:

Sub CreateCurveData()
    Dim i As Double
    Dim x As Double
    Dim y As Double
    
    '设置数据范围
    Dim xMin As Double
    Dim xMax As Double
    Dim yMin As Double
    Dim yMax As Double
    xMin = 0
    xMax = 5.5
    yMin = 0
    yMax = 3.5
    
    '设置数据点间隔
    Dim stepSize As Double
    stepSize = 0.1
    
    '清空工作表
    Worksheets("Sheet1").Cells.ClearContents
    
    '创建表头
    Worksheets("Sheet1").Cells(1, 1).Value = "X"
    Worksheets("Sheet1").Cells(1, 2).Value = "Y"
    
    '循环生成数据
    i = 1
    x = xMin
    Do While x <= xMax
        y = 3.5 * ((x / 5.5) ^ 2) * ((1 - (x / 5.5)) ^ 3)
        Worksheets("Sheet1").Cells(i + 1, 1).Value = x
        Worksheets("Sheet1").Cells(i + 1, 2).Value = y
        i = i + 1
        x = x + stepSize
    Loop
    
    '设置纵坐标范围
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.Axes(xlValue).MinimumScale = yMin
    ActiveChart.Axes(xlValue).MaximumScale = yMax
    
    '设置横坐标范围
    ActiveChart.Axes(xlCategory).MinimumScale = xMin
    ActiveChart.Axes(xlCategory).MaximumScale = xMax
End Sub

该代码将在工作表“Sheet1”上生成一组数据,用于绘制一个弯曲上升的曲线。数据点间隔为 0.1,纵坐标范围为 0-3.5,横坐标范围为 0-5.5。曲线的方程为 y = 3.5 * ((x / 5.5) ^ 2) * ((1 - (x / 5.5)) ^ 3)。生成的数据将自动绘制为一个图表,并且该图表的坐标轴范围将自动设置为指定的范围。

VBA 生成弯曲上升曲线数据:纵坐标 0-3.5,横坐标 0-5.5

原文地址: https://www.cveoy.top/t/topic/ogcf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录