简体   繁体   English

VBA + Matlab:饼图麻烦

[英]VBA + Matlab: Pie Chart trouble

My task is 'create pie chart in excel and then show it in matlab'. 我的任务是“在excel中创建饼图,然后在matlab中显示它”。

as i think, i have two troubles: 我认为,我有两个麻烦:

1) is this chart correctly create chart? 1)此图表是否正确创建图表? (A1-A6 are names, B1-B6 - numbers). (A1-A6是名称,B1-B6-是数字)。

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 ) 2)如何与此程序交互(在将来的功能中 ,返回图表)

using matlab and draw this pie chart in matlab? 使用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

This code doesn't work! 该代码不起作用! (i don't know how to rewrite string (我不知道如何重写字符串

ActiveChart.SetSourceData Source:=new_sheet.Range("A1:B6"), PloBy = xlColumns ) ActiveChart.SetSourceData Source:=new_sheet.Range("A1:B6"), PloBy = xlColumns

PS: I think it is better to load script from excel file and return Chart. PS:我认为最好从excel文件加载脚本并返回Chart。

But how to work with this chart in matlab? 但是如何在Matlab中使用此图表呢? (and draw it) (画出来)

您始终可以使用xlsread将excel值加载到matlab并使用piepie3在matlab自身中绘制饼图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM