Insert Chart in Excel with Excel data with Matlab
5 views (last 30 days)
Show older comments
I would like to apply this chart to all 16 sheets in the workbook. How can I do this?
Excel = actxserver('Excel.Application');
ResultFile = [pwd '\data.xls']; %USER INPUT: name of file within folder Workbook = invoke(Excel.Workbooks,'Open', ResultFile); %Error is apparently here
set(Excel, 'Visible' ,1);
%% Creating Charts
Chart = Excel.ActiveSheet.Shapes.AddChart; Chart.Name = 'ExperimentChart';
ExpChart = Excel.ActiveSheet.ChartObjects('ExperimentChart'); 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');
catch e
end
resultsheet = '1917001.dat';
NewSeries = invoke(Excel.ActiveChart.SeriesCollection,'NewSeries'); NewSeries.XValues = ['=' resultsheet '!A' int2str(3) ':A' int2str(999)]; NewSeries.Values = ['=' resultsheet '!B' int2str(2) ':B' int2str(999)]; NewSeries.Name = ['=' resultsheet '!B' int2str(1) ];
%Chart Style Excel.ActiveChart.ChartType = 'xlXYScatterLinesNoMarkers';
%Set the Axes
% Set the x-axis
Axes = invoke(Excel.ActiveChart,'Axes',1); set(Axes,'HasTitle',1); set(Axes.AxisTitle,'Caption','Time(s)')
% Set the y-axis
Axes = invoke(Excel.ActiveChart,'Axes',2); set(Axes,'HasTitle',1); set(Axes.AxisTitle,'Caption','RPM')
% % Give the Chart a title Excel.ActiveChart.HasTitle = 1; Excel.ActiveChart.ChartTitle.Characters.Text = 'RPM vs. Time';
% Resize the Chart
ExpChart.Width = 350; ExpChart.Height= 200; ExpChart.Left= 300; ExpChart.Top= 50;
0 Comments
Answers (1)
Roger Wohlwend
on 28 May 2014
Matlab cannot find the Excel file. Make sure that your path and file name are correct.
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!