我的任务是'在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
)
P.S:我认为最好从excel文件加载脚本并返回Chart。
但是如何在matlab中使用此图表? (画出来)