我的任务是“在 excel 中创建饼图,然后在 matlab 中显示”。
我认为,我有两个麻烦:
1) 此图表是否正确创建图表?(A1-A6 是名称,B1-B6 - 数字)。
好的,这个功能起作用了。
Function CreateChart() As Excel.Chart
Dim title As String
title = "One"
Dim Book As Workbook
Set Book = ThisWorkbook
Dim new_sheet As Excel.Worksheet
Set new_sheet = Book.Sheets(1)
Dim new_chart As Excel.Chart
Set new_chart = Charts.Add()
ActiveChart.ChartType = xlPie
ActiveChart.SetSourceData Source:=new_sheet.Range("A1:B6"), _
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAutomatic, Name:=title
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = title
End With
Set CreateChart = new_chart
End Function
2)如何与这个程序交互(在未来 -功能,返回图表)
使用matlab并在matlab中绘制这个饼图?
function chart = CreateChart( DataMatrix )
pie = actxserver('Excel.Chart');
all_pies = actxserver('Excel.Charts');
pietype = actxserver('Excel.XlChartType');
pie = all_pies.Add();
pie.ChartType = pietype.xlPie;
% here is a trouble to put data from matrix
pie.SetSourceData Source DataMatrix %hm.. strange
end
此代码不起作用!(我不知道如何重写字符串
ActiveChart.SetSourceData Source:=new_sheet.Range("A1:B6"), PloBy = xlColumns
)
PS:我认为最好从excel文件加载脚本并返回图表。
但是如何在matlab中使用这个图表呢?(并画出来)