How to set programmatically set ScaleType to Logarithmic in Excel Plot

1 次查看(过去 30 天)
I have code that successfully opens an Excel workbook in office 365 and plots data in an XYScatter plot. However, I wish for both the X and Y axes to have logarithmic scales but unfortunatley I cannot find the correct enumeration with what I believe is the correct axes property "ScaleType". I have tried two alternative enumerations:
  1. ScaleType = 'xlLogarithmic' For this I get the error "There is no enumerated value named 'xlLogarithmic'."
  2. ScaleType = 'xlScaleLogarithmic'; For this I get the error "Invoke Error, Dispatch Exception: Unspecified error
Here is my code
excelApp = actxserver('Excel.Application');
myWorkBook = excelApp.workbooks.Add;
workSheets = myWorkBook.Sheets;
myWorkSheet = excelApp.Activesheet ;
line{1} = myPlots.SeriesCollection.NewSeries;
myPlots.SeriesCollection(1).XValue = myWorkSheet.Range('A2:A24');
myPlots.SeriesCollection(1).Values = myWorkSheet.Range('B2:B24');
line{1}.ChartType = 'xlXYScatterLinesNoMarkers';
%Below is where i get the error for either approach
myPlots.Axes(1).ScaleType = 'xlLogarithmic';
myPlots.Axes(1).ScaleType = 'xlScaleLogarithmic';
Any suggestions?
Thanks

回答(1 个)

Rohit Kulkarni
Rohit Kulkarni 2023-8-31
Hi Scott,
I understand that you are facing the error in using the ScaleType property. According to the Excel Documentation there are two xlScaleType enumerations, xlScaleLinear and xlScaleLogarithmic.
xlScaleLogarithmic is used to set the scale to logarithmic.
Use xlScaleLogarithmic in the following way:
myPlots("myPlot1").Axes(xlValue).ScaleType =xlScaleLogarithmic
This will set the value axis in myPlot1 to use a logarithmic scale.
Refer the documentation link for details:
Hope it helps!

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by