如何繪製表面圖
回答
嗯,你必須(-5在本例中,以5 0.1步)創建meshgrid選擇正確的採樣。 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
如果你想一個有意義的顏色只研究顏色映射功能,這是非常簡單的。
如果你可以用一些評論解密你的代碼,那將是非常有幫助的,我無法遵循它。 – Sm1 2010-12-20 04:05:57
這可能不是你要找的答案,但我認爲它可以幫助你
我面臨同樣的問題,當我不得不繪製卡普蘭 - 邁耶存活曲線編程
我們所做的事情(我和我的團隊)是第一個得到公式然後我們構建了一個數據表使用這個公式。
一旦形成的數據表是爲圖表控制其中作爲優選可以編輯視覺輸出的數據源。
看看下面的代碼(它只是它的一部分)有一個想法。如果你需要更多的代碼,請讓我知道
'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
這與Matlab有什麼關係?它看起來像視覺基礎。 – 2010-12-14 14:13:50
謝謝Mokokamello,儘管它在VB中,但我仍然感激你的時間和耐心。 – Sm1 2010-12-20 03:58:04
- 1. 如何繪製表面視圖?
- 2. Rails:如何繪製圖表?
- 3. 如何繪製圖表?
- 4. 如何在Coldfusion中繪製面積圖
- 5. 如何用ggplot繪製黃土表面
- 6. 如何使用delphi繪製VLC表面
- 7. 使用ANativeWindow繪製表面貼圖/表面貼圖
- 8. 繪製圖表
- 9. 繪製圖表
- 10. 在Octave表面圖上繪製3D線
- 11. 在3D表面上繪製圖像[Matplotlib]
- 12. 如何繪製圖
- 13. 如何通過ios-charts繪製水平堆積面積圖表
- 14. 如何在Android中繪製表面視圖畫布
- 15. Java:如何在儘可能小的表面上繪製圖像?
- 16. 如何繪製心率圖表?
- 17. 如何繪製圖表控件?
- 18. 如何用OFC Python繪製圖表?
- 19. 如何在Swing中繪製此圖表?
- 20. 如何在netlogo中繪製圖表
- 21. 如何在ios圖表中繪製CombinedChart
- 22. 如何使用Chart.JS繪製圖表?
- 23. 如何爲geopandas繪製表格圖例
- 24. 如何在MATLAB中繪製圖表?
- 25. 如何使用rhomobile繪製圖表
- 26. 如何使用draw2d繪製圖表?
- 27. 如何用CAShapeLayer繪製圖表?
- 28. 如何在Mathematica中繪製圖表?
- 29. 如何在圖表上繪製線條?
- 30. javafx如何實時繪製圖表
只需按照http://www.mathworks.com/help/techdoc/ref/surf.html中的示例 – Mikhail 2010-12-14 12:12:00