Excel VBA 到 MATLAB 转换以创建具有一个 Y 轴和两个 X 轴的图表
Excel VBA to MATLAB conversion to create a diagram with one Y axis and two X axes
我想将图表创建-Excel-VBA 代码转换为 Matlab 脚本,这样我就可以在不处理 excel,并提前由 Matlab script.Thanks。
VBA代码如下:
Sub qwer()
'
' qwer Makro
' This macro creates a diagram with an X axis and two Y axes
Sheets("Loadcase1").Select
Range("D39:E39").Select
Selection.Copy
Sheets("Overview").Select
Range("B60").Select
ActiveSheet.Paste
Range("H15").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterSmooth
Application.CutCopyMode = False
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "=""Min Film Thickness mean"""
ActiveChart.SeriesCollection(1).XValues = "=Overview!$C:$H"
ActiveChart.SeriesCollection(1).Values = "=Overview!$C:$H"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "=""Sommerfeld Number"""
ActiveChart.SeriesCollection(2).XValues = "=Overview!$C:$H"
ActiveChart.SeriesCollection(2).Values = "=Overview!$C:$H"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(3).Name = "=""Min Film Thickness Min"""
ActiveChart.SeriesCollection(3).XValues = "=Overview!$C:$H"
ActiveChart.SeriesCollection(3).Values = "=Overview!$B:$B"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(4).Name = "=""Min Film Thickness Max"""
ActiveChart.SeriesCollection(4).XValues = "=Overview!$C:$H"
ActiveChart.SeriesCollection(4).Values = "=Overview!$C:$C"
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).AxisGroup = 2
End Sub
我找到了解决我自己问题的方法。关于matlab代码如下:
%% Excel Diagramm Versuch2
clc; clear all; close all;
excel = actxserver('excel.application');
excel.Visible = 1;
wkbk = excel.Workbooks.Open('Z:\...file directory...\V1.xlsx');
wkbk.ActiveSheet;
wkbk.ActiveSheet.Shapes.AddChart.Select;
wkbk.ActiveChart.ChartType = 'XlXYScatterSmoothNoMarkers';
% qwer makro Anfang
wkbk.Sheet.Item('Tabelle2').Select;
wkbk.Sheet.Item('Tabelle1').Select;
wkbk.ActiveChart;
% Set the x-axis
Axes = invoke(excel.ActiveChart,'Axes',1);
set(Axes,'HasTitle',1);
set(Axes.AxisTitle,'Caption','Revolution[1/min]')
% Set the y-axis
Axes = invoke(excel.ActiveChart,'Axes',2);
set(Axes,'HasTitle',1);
set(Axes.AxisTitle,'Caption','Film Thickness[µm]')
% Give the Chart a title
excel.ActiveChart.HasTitle = 1;
excel.ActiveChart.ChartTitle.Characters.Text = 'Film Thickness-Revolution';
invoke(excel.ActiveChart.SeriesCollection,'NewSeries');
wkbk.ActiveChart.SeriesCollection(1).Name = 'Min Film Thickness mean';
wkbk.ActiveChart.SeriesCollection(1).XValues = 'Tabelle1!$A:$A';
wkbk.ActiveChart.SeriesCollection(1).Values = 'Tabelle1!$B:$B';
invoke(excel.ActiveChart.SeriesCollection,'NewSeries');
wkbk.ActiveChart.SeriesCollection(2).Name = 'Sommerfeld Number';
wkbk.ActiveChart.SeriesCollection(2).XValues = 'Tabelle2!$A:$A';
wkbk.ActiveChart.SeriesCollection(2).Values = 'Tabelle2!$B:$B';
wkbk.ActiveChart.SeriesCollection(2).AxisGroup = 2;
pause(20)
wkbk.Close;
excel.Quit;
close excel
我想将图表创建-Excel-VBA 代码转换为 Matlab 脚本,这样我就可以在不处理 excel,并提前由 Matlab script.Thanks。
VBA代码如下:
Sub qwer()
'
' qwer Makro
' This macro creates a diagram with an X axis and two Y axes
Sheets("Loadcase1").Select
Range("D39:E39").Select
Selection.Copy
Sheets("Overview").Select
Range("B60").Select
ActiveSheet.Paste
Range("H15").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterSmooth
Application.CutCopyMode = False
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "=""Min Film Thickness mean"""
ActiveChart.SeriesCollection(1).XValues = "=Overview!$C:$H"
ActiveChart.SeriesCollection(1).Values = "=Overview!$C:$H"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "=""Sommerfeld Number"""
ActiveChart.SeriesCollection(2).XValues = "=Overview!$C:$H"
ActiveChart.SeriesCollection(2).Values = "=Overview!$C:$H"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(3).Name = "=""Min Film Thickness Min"""
ActiveChart.SeriesCollection(3).XValues = "=Overview!$C:$H"
ActiveChart.SeriesCollection(3).Values = "=Overview!$B:$B"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(4).Name = "=""Min Film Thickness Max"""
ActiveChart.SeriesCollection(4).XValues = "=Overview!$C:$H"
ActiveChart.SeriesCollection(4).Values = "=Overview!$C:$C"
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).AxisGroup = 2
End Sub
我找到了解决我自己问题的方法。关于matlab代码如下:
%% Excel Diagramm Versuch2
clc; clear all; close all;
excel = actxserver('excel.application');
excel.Visible = 1;
wkbk = excel.Workbooks.Open('Z:\...file directory...\V1.xlsx');
wkbk.ActiveSheet;
wkbk.ActiveSheet.Shapes.AddChart.Select;
wkbk.ActiveChart.ChartType = 'XlXYScatterSmoothNoMarkers';
% qwer makro Anfang
wkbk.Sheet.Item('Tabelle2').Select;
wkbk.Sheet.Item('Tabelle1').Select;
wkbk.ActiveChart;
% Set the x-axis
Axes = invoke(excel.ActiveChart,'Axes',1);
set(Axes,'HasTitle',1);
set(Axes.AxisTitle,'Caption','Revolution[1/min]')
% Set the y-axis
Axes = invoke(excel.ActiveChart,'Axes',2);
set(Axes,'HasTitle',1);
set(Axes.AxisTitle,'Caption','Film Thickness[µm]')
% Give the Chart a title
excel.ActiveChart.HasTitle = 1;
excel.ActiveChart.ChartTitle.Characters.Text = 'Film Thickness-Revolution';
invoke(excel.ActiveChart.SeriesCollection,'NewSeries');
wkbk.ActiveChart.SeriesCollection(1).Name = 'Min Film Thickness mean';
wkbk.ActiveChart.SeriesCollection(1).XValues = 'Tabelle1!$A:$A';
wkbk.ActiveChart.SeriesCollection(1).Values = 'Tabelle1!$B:$B';
invoke(excel.ActiveChart.SeriesCollection,'NewSeries');
wkbk.ActiveChart.SeriesCollection(2).Name = 'Sommerfeld Number';
wkbk.ActiveChart.SeriesCollection(2).XValues = 'Tabelle2!$A:$A';
wkbk.ActiveChart.SeriesCollection(2).Values = 'Tabelle2!$B:$B';
wkbk.ActiveChart.SeriesCollection(2).AxisGroup = 2;
pause(20)
wkbk.Close;
excel.Quit;
close excel