From: Morgan Fox on
I have written a script which looks in a directory, calls up appropriate files, and analyzes them all one at a time with a for loop. It takes data from an excel file, manipulates it, and saves it to a new excel file. I need an excel plot as well as the data in the new excel file... is there a way to have excel create a plot through MATLAB? I know I can send a MATLAB plot to excel with xlswritefig, but that's not exactly what I'm going for.

Any ideas?

Thanks
From: Andy on
"Morgan Fox" <mdf8(a)duke.edu> wrote in message <i1njgq$1og$1(a)fred.mathworks.com>...
> I have written a script which looks in a directory, calls up appropriate files, and analyzes them all one at a time with a for loop. It takes data from an excel file, manipulates it, and saves it to a new excel file. I need an excel plot as well as the data in the new excel file... is there a way to have excel create a plot through MATLAB? I know I can send a MATLAB plot to excel with xlswritefig, but that's not exactly what I'm going for.
>
> Any ideas?
>
> Thanks

You can use actxserver to have very fine control of Excel documents in MATLAB. Here is some sample code to get you started, but you should spend lots of time reading the documentation and exploring the Excel objects.



%%

e = actxserver('excel.application');
eWs = e.Workbooks;
eW = eWs.Add;
eS = eW.ActiveSheet;
e.Visible = 1;

%%

x=sin(1:100)';
eS.Range('A1:A100').Value = x;

%%

eCO = eS.ChartObjects.Add(100, 30, 400, 250);
eCO.Chart.ChartWizard(eS.Range('A1:A100'));
eCO.Chart.ChartType = 1; % view the chart before moving on

%%

eCO.Chart.ChartType = 65; % view it again

%%

eCO.Chart.HasTitle = true;
eCO.Chart.ChartTitle.Text = 'This is the title text'; % view it again

%%

eW.Close;
e.Quit;
delete(e)
From: Morgan Fox on
Andy, I think that will work. I appreciate it.
From: Andy on
% Apologies for my previous post. The following is better:

%%

e = actxserver('excel.application');
eWs = e.Workbooks;
eW = eWs.Add;
eS = eW.ActiveSheet;
e.Visible = 1;

%%

x=(0:2:100)';
y=sin(x);
eS.Range('A1:B50').Value = [x y];

%%

eCO = eS.ChartObjects.Add(100, 30, 400, 250);
eC = eCO.Chart;
eC.SeriesCollection.NewSeries;
% better control of the data if the line number
% is not your x-axis
eC.SeriesCollection(1).Value = eS.Range('B1:B50');
eC.SeriesCollection(1).XValue = eS.Range('A1:A50');

%%

eCO.Chart.ChartType = 1; % view the chart before moving on

%%

eCO.Chart.ChartType = 65; % view it again

%%

eCO.Chart.HasTitle = true;
eCO.Chart.ChartTitle.Text = 'This is the title text'; % view it again

%%

eW.Close;
e.Quit;
delete(e)