import matlab.engine as matlabEngine
def __init__(self, action):
self.time_start = time.time()
def __exit__(self, *args, **kwargs):
print('Done in %0.3f seconds'
modelname = 'simpleModel'
with LogTime('Starting Matlab Engine'):
m = matlabEngine.start_matlab();
t = np.linspace(0,stopTime,nbPoints)
voltage = 120*math.sqrt(2)*np.sin(2*math.pi*60*t)
current = 120*math.sqrt(2)*np.sin(2*math.pi*60*t + math.pi/8)
# Numpy to matlab conversion
t = matlab.double(t.tolist())
voltage = matlab.double(voltage.tolist())
current = matlab.double(current.tolist())
# Write to workspace for model
m.workspace['input_voltage'] = m.timeseries(voltage, t)
m.workspace['input_current'] = m.timeseries(current, t)
with LogTime('Loading Model'):
m.load_system(modelname, nargout=0)
m.set_param(modelname, 'StopTime', str(stopTime), 'FixedStep', str(simstep), nargout=0)
with LogTime('Running simulation'):
out = m.sim(modelname) # Empty object. don't know what to do with it.