Effacer les filtres
Effacer les filtres

How to set programmatically set ScaleType to Logarithmic in Excel Plot

6 vues (au cours des 30 derniers jours)
Scott
Scott le 25 Août 2022
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

Réponses (1)

Rohit Kulkarni
Rohit Kulkarni le 31 Août 2023
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!

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by