My task is 'create pie chart in excel and then show it in matlab'.
as i think, i have two troubles:
1) is this chart correctly create chart? (A1-A6 are names, B1-B6 - numbers).
Ok, this function work.
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) How to interact with this procedure ( in future - function, returning Chart )
using matlab and draw this pie chart in 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
This code doesn't work! (i don't know how to rewrite string
ActiveChart.SetSourceData Source:=new_sheet.Range("A1:B6"), PloBy = xlColumns
)
P.S: I think it is better to load script from excel file and return Chart.
But how to work with this chart in matlab? (and draw it)