Creating errorbars in excel

3 ビュー (過去 30 日間)
Willem
Willem 2012 年 3 月 22 日
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.

採用された回答

Eric
Eric 2012 年 3 月 22 日
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 件のコメント
Willem
Willem 2012 年 3 月 23 日
Tank you, this is exactly what I needed!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeErrorbars についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by