From: Francki on
Hi guys,

well I've manage to plot a set a a graphs in excel using matlab via the actxserver of course.......and I almost succeeded except There is a little bump in the road that I encountered.

2....I'm trying to change the gap width of data to 50
1....the alignment of the data on the x-axis has to be pointing upwards
3.....make the graph display the values and set them to 1 d.p.

Here is what I've comeup with (of course matlab keep returning errors):

exl= actxserver('excel.application');
dr='C:\Users\Me\Desktop\';
file='Templatexls.xls';
% Load data from an excel file
% Get Workbook interface and open file
exl.visible = true;
exlWkbk = exl.Workbooks;
exlFile = exlWkbk.Open([dr file]);
exlSheetchartinlap=exlFile.Charts.Item('InLap comparison');
.....................................................................................
......................................................................................
Problem 1: Matlab doesn't recognise code????
......................................................................................
exlSheetchartinlap.Axes(xlCategory).Select;
exlSheetchartinlap.Axes(xlCategory).TickLabels.Alignment='xlCenter';
exlSheetchartinlap.Axes(xlCategory).TickLabels.Offset = 100;
exlSheetchartinlap.Axes(xlCategory).TickLabels.ReadingOrder=1;
exlSheetchartinlap.Axes(xlCategory).TickLabels.Orientation = 'xlUpward';
......................................................................................
Problem 2: yet another vba (macro) code matlab doesn't recognise
......................................................................................
exlSheetchartinlap.SeriesCollection(1).ChartGroups(1).Overlap=0;
exlSheetchartinlap.SeriesCollection(1).ChartGroups(1).GapWidth = 50;
exlSheetchartinlap.SeriesCollection(1).ChartGroups(1).HasSeriesLines='False';
exlSheetchartinlap.SeriesCollection(1).ChartGroups(1).VaryByCategories = 0;
......................................................................................
Problem 3: code not working still
......................................................................................
exlSheetchartinlap.ApplyDataLabels.AutoText='True';
exlSheetchartinlap.ApplyDataLabels.LegendKey='True';
exlSheetchartinlap.ApplyDataLabels.HasLeaderLines='False';
exlSheetchartinlap.ApplyDataLabels.ShowSeriesName='False';
exlSheetchartinlap.ApplyDataLabels.ShowCategoryName='False';
exlSheetchartinlap.ApplyDataLabels.ShowValue='True';
exlSheetchartinlap.ApplyDataLabels.ShowPercentage='False';
exlSheetchartinlap.ApplyDataLabels.ShowBubbleSize='False';
exlSheetchartinlap.SeriesCollection(1).DataLabels.NumberFormat='0.0';

I've tried every combination possible and I'm about to quit but i thought there might an expert here that can sort things out.....Help out sorting my problems please!!
anyone!

Regards!
From: Andy on
You need to describe the problems you're having much more specifically. "MATLAB doesn't recognize the code" and "it doesn't work" don't give us a lot to go on. It would be more helpful to post error messages or unexpected output. I'm not at MATLAB right now, but here are some quick things to check that might be giving you problems:

1. Many constant values from the Excel documentation that VB will understand (e.g. xlCategory, xlCenter, xlUpward, etc.) are not understood by MATLAB. Use trial and error or see the following to help convert these to MATLAB-friendly arguments: http://undocumentedmatlab.com/blog/com-activex-tips/

2. Collection objects in VB support calls such as SeriesCollection(1) and ChartGroups(1), but MATLAB frequently needs these to be of the form SeriesCollection.Item(1) and ChartGroups.Item(1). (Actually, I think the SeriesCollection(1) is okay, but I can't remember. And the 'collection object'.Item(1) will always work, so get in the habit of using that instead.) See: the same link as above.