www.omatrix.com





:: O-Matrix ::
> Overview
> Examples
> Performance
> Analysis Functions
> Data Visualization
> The O-Matrix Language
> Data Manipulation/IO
> Application Development
> Using Matlab m-files




XLRUNMACRO.OMS

Script File:
# XLRunMacro.oms
# Automation Server: Microsoft Excel
# Simulates an AR(1) process, estimates its spectrum
# and creates an XY plot in Microsoft Excel using VBA
# (This example is derived from the ar1sim.oms example
# in the example\demo directory)
# Transfer O-Matrix variable to Excel at the given range
local function putXLMat(matVar, range) begin
	cowith("Range", range)
	copropput("Value", matVar)
	coendwith
end
# the AR coefficient
a = .8
# the covariance at lags 0 and 1 (see Equation 3.5.16)
r = {1., a} / (1 - a^2)  
# number of realizations of the process
M = 10
# number of points in each realization
N = 100
# compute the realizations
x = arcov(N, M, r)
# fractional bandwidth for the DPSS taper
w = 2. / N 
# compute the dpss taper
taper = dpss(N, 1, w)
# time between data points
dt = 1
# compute the spectral estimate
estimate = fspec(x, dt, taper)
# spacing between frequency points
df = 1. / (N * dt)
# grid of frequency values start at -(N / 2) * df
f = (seq(N) - N / 2 - 1) * df
# radial frequency
omega = 2 * PI * f
# true spectrum (see example 1 on page 281)
spectrum = 1. / (1 - 2 * a*cos(omega) + a^2)
#
## script entry point
cocreate("Excel.Application")
copropput("Visible", 1)
fileName = [OM_INSTALL,"\example\automation\XLRunMacro.xls"]
cowith("Workbooks")
coinvoke("Open", fileName)
coendwith
# Transfer the O-Matrix data to first three columns of the opened worksheet
cowith("ActiveSheet")
putXLMat([f, spectrum, estimate], "A1:C100")
coendwith
# Run the VBA macro 'CreateARPlot' to create an Excel XY chart
coinvoke("Run","CreateARPlot")
	  

Output:


Company |  Products |  Showcase |  Support |  Ordering
Copyright© 1994-2009 Harmonic Software Inc. - All rights reserved.