필터 지우기
필터 지우기

How to set programmatically set ScaleType to Logarithmic in Excel Plot

조회 수: 6 (최근 30일)
Scott
Scott 2022년 8월 25일
답변: Rohit Kulkarni 2023년 8월 31일
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에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by