Excel Bubble Chart Code
Show older comments
I am trying to model a pulley system in excel from a code that will calculate belt tension. I have tried to plot the system in matlab but was having trouble scaling the size of the markers to be the correct diameter so I created a matlab code that will generate an excel file and plot the data from the belt tension code as a Bubble Chart. My problem is that I have a specified diameter for each pulley. I can manually set the Bubble size in excel to be the appropriate diameter but given that we are going to be constantly changing these values, having matlab set the bubble size would be ideal. Currently it models each pulley as the same size in their appropriate X and Y coordinates. Any help would be greatly appreciated! PulleyTable is sample data and below is a copy of the code:
PulleyTable = table({'CRK','IDL3','AT1','ALT','AT2','WP','IDL1','AC','IDL2'}', ...
[0;123.6;185.27;260.42;228.77;138.84;-62.55;-268.3;41],...
[0;2.2;46.86;58.25;127.35;190.34;182.38;98.3;121],...
[164.16;62.26;57.26;60.56;57.26;124.36;72.26;116.26;72.26],logical([1 0 0 1 0 1 0 1 0]'),...'VariableNames',{'Name','X','Y','D','In_Out'});
PulleyTable.Properties.VariableUnits({'X','Y','D','In_Out'})={'mm','mm','mm','CCW'};
filename = 'pulleygraph.xlsx';
writetable(PulleyTable,filename,'Sheet',1,'Range','A1');
Excel = actxserver('Excel.Application');
ResultFile = ['...\pulleygraph.xlsx'];
Workbook = invoke(Excel.Workbooks,'Open',ResultFile);
set(Excel,'Visible',1);
Chart = Excel.ActiveSheet.Shapes.AddChart;
Chart.Name = 'NanoPulley';
ExpChart = Excel.ActiveSheet.ChartObjects('NanoPulley');
ExpChart.Activate;
try
Series = invoke(Excel.ActiveChart,'SeriesCollection',1);
invoke(Series,'Delete');
Series = invoke(Excel.ActiveChart,'SeriesCollection',1);
invoke(Series,'Delete');
Series = invoke(Excel.ActiveChart,'SeriesCollection',1);
invoke(Series,'Delete');
Series = invoke(Excel.ActiveChart,'SeriesCollection',1);
invoke(Series,'Delete');
Series = invoke(Excel.ActiveChart,'SeriesCollection',1);
invoke(Series,'Delete');
Series = invoke(Excel.ActiveChart,'SeriesCollection',1);
invoke(Series,'Delete');
Series = invoke(Excel.ActiveChart,'SeriesCollection',1);
invoke(Series,'Delete');
Series = invoke(Excel.ActiveChart,'SeriesCollection',1);
invoke(Series,'Delete');
catch e
end
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
NewSeries.XValues = ['=' 'Sheet1' '!B' int2str(2)];
NewSeries.Values = ['=' 'Sheet1' '!C' int2str(2)];
NewSeries.Name = ['=' 'Sheet1' '!A' int2str(2)];
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
NewSeries.XValues = ['=' 'Sheet1' '!B' int2str(3)];
NewSeries.Values = ['=' 'Sheet1' '!C' int2str(3)];
NewSeries.Name = ['=' 'Sheet1' '!A' int2str(3)];
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
NewSeries.XValues = ['=' 'Sheet1' '!B' int2str(4)];
NewSeries.Values = ['=' 'Sheet1' '!C' int2str(4)];
NewSeries.Name = ['=' 'Sheet1' '!A' int2str(4)];
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
NewSeries.XValues = ['=' 'Sheet1' '!B' int2str(5)];
NewSeries.Values = ['=' 'Sheet1' '!C' int2str(5)];
NewSeries.Name = ['=' 'Sheet1' '!A' int2str(5)];
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
NewSeries.XValues = ['=' 'Sheet1' '!B' int2str(6)];
NewSeries.Values = ['=' 'Sheet1' '!C' int2str(6)];
NewSeries.Name = ['=' 'Sheet1' '!A' int2str(6)];
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
NewSeries.XValues = ['=' 'Sheet1' '!B' int2str(7)];
NewSeries.Values = ['=' 'Sheet1' '!C' int2str(7)];
NewSeries.Name = ['=' 'Sheet1' '!A' int2str(7)];
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
NewSeries.XValues = ['=' 'Sheet1' '!B' int2str(8)];
NewSeries.Values = ['=' 'Sheet1' '!C' int2str(8)];
NewSeries.Name = ['=' 'Sheet1' '!A' int2str(8)];
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
NewSeries.XValues = ['=' 'Sheet1' '!B' int2str(9)];
NewSeries.Values = ['=' 'Sheet1' '!C' int2str(9)];
NewSeries.Name = ['=' 'Sheet1' '!A' int2str(9)];
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries');
NewSeries.XValues = ['=' 'Sheet1' '!B' int2str(10)];
NewSeries.Values = ['=' 'Sheet1' '!C' int2str(10)];
NewSeries.Name = ['=' 'Sheet1' '!A' int2str(10)];
Excel.ActiveChart.ChartType = 'xlBubble';
Axes = invoke(Excel.ActiveChart,'Axes',1);
set(Axes,'HasTitle',1);
set(Axes.AxisTitle,'Caption','X')
Axes = invoke(Excel.ActiveChart,'Axes',2);
set(Axes,'HasTitle',1);
set(Axes.AxisTitle,'Caption','Y')
Excel.ActiveChart.HasTitle = 1;
Excel.ActiveChart.ChartTitle.Characters.Text = 'Nano Pulley System';
invoke(Excel.ActiveWorkbook,'Save');
Excel.Quit;
Excel.delete;
clear Excel;
6 Comments
The question asked is Excel, not Matlab; the place for that would in an Excel forum/newsgroup.
..." tried to plot the system in matlab but was having trouble scaling the size of the markers to fit the input data"
OTOH, if you'll show us what you've done and provide some sample data folks can use to replicate the plot, more than likely someone here can solve the issue in Matlab in "much more simpler" fashion.
Cameron Martineau
on 19 Jun 2017
dpb
on 21 Jun 2017
It's trying to manipulate Excel, though...and it won't run here...it took about a half-dozen restarts to get this far and I don't know Excel lingo enough to try to work out the bugs in an older release...
>> cam
Error using Interface.Microsoft_Excel_9.0_Object_Library.Workbooks/Open
Invoke Error, Dispatch Exception:
Source: Microsoft Excel
Description: 'pulleygraph.xls' could not be found.
Check the spelling of the file name, and verify that the file
location is correct.
...
Error in cam (line 12)
Workbook = invoke(Excel.Workbooks,'Open',ResultFile);
>>
>> ResultFile
ResultFile =
pulleygraph.xls
>> dir p*.xls
pulleygraph.xls
>>
Attach the image of the graph you did create and tell us what isn't as you want/what you would expect/want instead.
dpb
on 21 Jun 2017
OK, I figured out the Open; Excel needs fully-qualified name...
ResultFile = fullfile(cd,'pulleygraph.xls');
did the open Excel, but almost immediately
>> cam
No appropriate method, property, or field AddChart for class Interface.Microsoft_Excel_9.0_Object_Library.Shapes.
Error in cam (line 14)
Chart = Excel.ActiveSheet.Shapes.AddChart;
>>
I give up ...
Cameron Martineau
on 21 Jun 2017
Accepted Answer
More Answers (0)
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

