How to set programmatically set ScaleType to Logarithmic in Excel Plot
1 view (last 30 days)
Show older comments
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:
- ScaleType = 'xlLogarithmic' For this I get the error "There is no enumerated value named 'xlLogarithmic'."
- 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
0 Comments
Answers (1)
Rohit Kulkarni
on 31 Aug 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!
0 Comments
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!