如何绘制表面图

时间:2010-12-14 08:17:38

标签: matlab surface

  

Matlab中是否有内置/ m文件   获得高度波动和   多个山峰的情节   高山功能?我想获得一个   3D中的类似数字是!alt textalt text

     

公式(可能)是

     
    

Z = SIN(X1)SIN(2次)\ {SQRT} X1X2

  

如何以多彩的说明性方式绘制高山,罗森布罗克,蛋箱功能等主要功能的表面图。请帮助您提供示例代码。

2 个答案:

答案 0 :(得分:1)

那么,你必须创建一个选择正确采样的网格网格(在这个例子中,从-5到5,步长为0.1)。在Z中,将函数的公式设为Z = f(X,Y)

X=[-5:0.1:5]; %% The X-axis goes from the value of -5 to +5 with a step of 0.1 (100 points)
Y=[-5:0.1:5]; %% like the X-axis
[wx,wy]=meshgrid(X,Y); %% see [MATLAB documentation][1]
Z=sinc(sqrt((wx-5).^2+wy.^2)); %% this is an example formula, substitute it with YOUR formula
fig=surfl(wx,wy,Z); %% make a surface plot with lighting
shading interp; %% optional, try to remove it.
colormap hot; %% here you decide the colormap: hot is the one going from white to red
view(45,40) %% optional, select the angle of view

如果你想要一个有意义的颜色,只需研究色彩映射功能,它就非常简单。

答案 1 :(得分:0)

这可能不是您正在寻找的答案,但我认为它可能对您有所帮助

当我不得不以编程方式绘制Kaplan Meier Survival Curve时,我遇到了同样的问题

我们做了什么(我和我的团队)首先获得公式然后我们构建了一个使用此公式的数据表

数据表形成后是数据源 图表控件,您可以在其中编辑可视输出。

查看下面的代码(它只是其中的一部分)有一个想法。如果您需要更多代码,请告诉我

  'Start generating the life tables

Dim myTable As New DataTable

myTable.Columns.Add("Survial Status")
myTable.Columns.Add("Remaining Patients")
myTable.Columns.Add("Survial Duration")
myTable.Columns.Add("Survial Propability")
myTable.Columns.Add("Cumulative Survial Propability")

Dim myFirstRow As DataRow = myTable.NewRow
myFirstRow.Item(0) = 1
myFirstRow.Item(1) = CasesCount
myFirstRow.Item(2) = 0
myFirstRow.Item(3) = 1
myFirstRow.Item(4) = 1

myTable.Rows.Add(myFirstRow)

Dim Ptnseq = CasesCount

For I = 1 To CasesCount

    Dim myRow As DataRow = myTable.NewRow

    'Get only one record  from KaplanTable
    Dim Kaplantmp = myReader.Read
    Ptnseq = Ptnseq - 1

    myRow.Item(0) = myReader.GetValue(2)
    myRow.Item(1) = Ptnseq 'Sets the total number of remaining patients
    myRow.Item(2) = myReader.GetValue(3)

    If myRow.Item(0) = 0 Then
        myRow.Item(3) = myTable.Rows(I - 1).Item(3)
        myRow.Item(4) = myTable.Rows(I - 1).Item(4)
    ElseIf myRow.Item(0) = 1 Then
        myRow.Item(3) = myRow.Item(1) / myTable.Rows(I - 1).Item(1)
        myRow.Item(4) = myRow.Item(3) * myTable.Rows(I - 1).Item(4)
    End If

    myTable.Rows.Add(myRow)

Next I

'Finished generating the lifetables, bind it to a grid

Dim myGrid As New GridView 'Create a new dynamc Grid
Dim myLabel As New Label 'Create a new dynamic label for this grid
myPage.Form.Controls.Add(myLabel) 'add the label, then
myPage.Form.Controls.Add(myGrid) 'add the grid
myGrid.DataSource = myTable 'Bind the grid to the calculated lifetables
myGrid.DataBind()

DrawKaplanCurve(myTable, myChart, Stratum)
myLabel.Text = "Current Stratum is: " & Stratum & "<br/>" & "Total Number of cases is: " & (myTable.Rows.Count - 1).ToString & " Cases"

Return myTable.Rows.Count - 1

End Function

Public Shared Sub DrawKaplanCurve(ByVal myTable As DataTable, ByVal myChart As Chart, ByVal Stratum As String)

Dim KaplanSeries As New Series
KaplanSeries.ChartType = SeriesChartType.StepLine
KaplanSeries.Name = Stratum

Dim CensoredSeries As New Series
CensoredSeries.ChartType = SeriesChartType.Stock
CensoredSeries.Name = "Censored " & Stratum

For I = 1 To myTable.Rows.Count - 1

    Dim myPoint As New DataPoint
    Dim xval As Double = myTable.Rows(I).Item(2)
    Dim yval As Double = myTable.Rows(I).Item(4)
    myPoint.SetValueXY(xval, yval)

    ' If alive case, then add to censored data
    If myTable.Rows(I).Item(0) = 0 Then
        Dim CensoredPoint As New DataPoint
        CensoredPoint.SetValueXY(myPoint.XValue, yval - 0.01, yval + 0.01)
        CensoredPoint.ToolTip = "Censored Case Number " & myTable.Rows(I).Item(1).ToString & vbNewLine & "Survival Duration = " & myTable.Rows(I).Item(2).ToString & " months" & vbNewLine & "Cumulative Survival Propability = " & Round(yval * 100, 2).ToString & "%"
        CensoredPoint.Color = myPoint.Color
        If I <> myTable.Rows.Count - 1 Then CensoredSeries.Points.Add(CensoredPoint) 'add all except the last point because it shouldn't be censored
    End If

    'myPoint.ToolTip = "Case Number " & myTable.Rows(I).Item(1).ToString & vbNewLine & "Survival Duration = " & myTable.Rows(I).Item(2).ToString & " months"
    If I = myTable.Rows.Count - 1 Then myPoint.Label = Round(yval * 100, 2).ToString & "%"
    KaplanSeries.Points.Add(myPoint)

Next

myChart.Series.Add(KaplanSeries)
myChart.Series.Add(CensoredSeries)
myChart.Series(CensoredSeries.Name).IsVisibleInLegend = False
Dim myLegend As New Legend
myLegend.TitleForeColor = myChart.Series(myChart.Series.Count - 1).Color
myChart.Legends.Add(myLegend)

End Sub