MATLAB: How to set the ‘HasAxis’ property of the Excel Chart object using ActiveX in MATLAB 7.11 (R2010b)

additionalargumentsMATLAB

The 'HasAxis' property is used to specify whether Excel will display the primary or secondary category, series, or value axes on a chart.
The property requires that the xlAxisType and xlAxisGroup arguments are specified when the property is accessed.
How do I do that using the ACTXCONTROL ActiveX support in MATLAB?
Information about 'HasAxis' is at:

Best Answer

The following example shows how to pass additional arguments to the SET and GET command to access a property that requires additional indexing.
% axis types: <http://msdn.microsoft.com/en-us/library/bb240966(v=office.12).aspx>
xlCategory = 1;
xlValue = 2;
% axis groups: <http://msdn.microsoft.com/en-us/library/bb240962(v=office.12).aspx>
xlPrimary = 1;
xlSecondary = 2;
% open Excel using ActiveX
xlApp = actxserver('Excel.Application');
% set it to be visible
xlApp.Visible = true;
% inhibit "Do You Want to Save" dialog when Excel is closed.
xlApp.DisplayAlerts = false;
% Add a new workbook
xlWbook = invoke(xlApp.Workbooks,'add');
% Add a blank chart to the workbook
xlChart = invoke(xlWbook.Charts,'add');
% Go to the first sheet in the workbook
xlSheet = xlWbook.Sheets.Item('Sheet1');
% insert some data
xlSheet.Range('A1:B3').Value = { 1 20 ; 2 80; 4 100 };
% set the chart to use the data for the bar values
xlChart.SetSourceData( xlSheet.Range('A1:B3'));
% get the second data series
xlS2 = xlChart.SeriesCollection.Item(2);
xlS2.AxisGroup = 'xlSecondary'; % set it to display on the secondary axis.
% get current state of primary x axis
get(xlChart,'HasAxis',xlCategory,xlPrimary)
%ans = 1
% turn off primary x axis
set(xlChart,'HasAxis',xlCategory,xlPrimary,0)
%ans = NaN
% verify that it's off
get(xlChart,'HasAxis',xlCategory,xlPrimary)
% ans = 0
% turn it back on
set(xlChart,'HasAxis',xlCategory,xlPrimary,1)
% ans = NaN
% verify that it's on
get(xlChart,'HasAxis',xlCategory,xlPrimary)
% ans = 1
% display a y axis for secondary data
set(xlChart, 'HasAxis', xlValue, xlSecondary, 1)