Creating errorbars in excel

1 view (last 30 days)
Willem
Willem on 22 Mar 2012
I´m trying to create a column graph with errorbars in excel from matlab, but I can´t find how to set the length of the error bars.
I think I know the method I should use, but I keep getting the error ??? No method 'ErrorBar' with matching signature found for class 'Interface.0002086B_0000_0000_C000_000000000046'.
even though 'ErrorBar' shows up as a method when I use methods() (the output is (Variant ErrorBar(handle, XlErrorBarDirection, XlErrorBarInclude, XlErrorBarType, Variant(Optional))
this is a part of the code I use:
------------------------------------------------------------ e = actxserver('excel.application'); eWs = e.Workbooks; eW = eWs.Add; eS = eW.ActiveSheet; e.Visible = 1;
%%
x=(0:2:10)';
eS.Range('A1:C6').Value = [x]; eCO = eS.ChartObjects.Add(100, 30, 400, 250); eC = eCO.Chart; eC.SeriesCollection.NewSeries;
eC.SeriesCollection(1).Value = eS.Range('A1:A6'); eC.SeriesCollection(1).HasErrorBars = 1; -------------------------------------------------------------------
to find the method I used methods(eC.SeriesCollection(1), '-full').
I found this site: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.series.errorbar.aspx which I think is about what I need but I can't figure it out.
Would be really gratefull if someone can help me.

Accepted Answer

Eric
Eric on 22 Mar 2012
You're on the right track. Here's how to set all of the error bars to 5:
[xlY, xlBoth, xlFixedValue] = deal(1);
eC.SeriesCollection(1).ErrorBar(xlY, xlBoth, xlFixedValue, 5);
Here's how to set the error bars to values specified in cells E1:E6 (positive extent of error bars) and F1:F6 (negative extent of error bars). The trick is to pass in Range objects for the last two inputs of ErrorBar().
xlCustom = -4114;
eC.SeriesCollection(1).ErrorBar(xlY, xlBoth, xlCustom, eS.Range('E1:E6'), eS.Range('F1:F6'));
Here's how to set them to 3% of the value:
xlPercent = 2;
eC.SeriesCollection(1).ErrorBar(xlY, xlBoth, xlPercent, 3);
A good way to get usages for COM functions in Excel is to use the macro recorder. Record the operation you want to code and then translate the VBA code to Matlab, being careful with Collection objects (which are indexed more easily in VBA than from the COM interface). You can look up the values for the enumerations by using the Immediate window in the VBA tool.
Good luck,
Eric
  1 Comment
Willem
Willem on 23 Mar 2012
Tank you, this is exactly what I needed!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!