sim
Run an nflow simulation of a model and return its results.
📝Syntax
out = sim(model)
out = sim(model, 'StopTime', T)
out = sim(model, 'StopTime', T, 'SampleTime', dt)
📥Input Arguments
Parameter Description
model a loaded system (name or handle) or the path to a .nflow file.
StopTime optional finite numeric scalar; overrides the model's total simulated time.
SampleTime optional finite numeric scalar; overrides the model's sample time.
📤Output Arguments
Parameter Description
out a structure with one field per To Workspace block (its VariableName) plus 'tout' (the time vector).
📄Description

sim runs an nflow simulation of model and returns its results.

From Workspace blocks read their signal from the base workspace, so define those variables before calling sim. To Workspace blocks write their result to the base workspace (as during an interactive run) and are also exposed as fields of out (for example out.simout).

This is a convenience wrapper over the headless runner __nflow_simulate__: it reads the model document, applies the optional StopTime / SampleTime overrides, runs the engine and collects the results.

StopFcn callback. If the model carries a top-level stopFcn field (a text blob of Nelson commands), it runs in the base workspace once the simulation stops, with the result exposed as out. It fires only from a simulation run (never on model load) and runs even when no output is requested, so a model whose stopFcn is NFlow.plotScopes(out) pops its scopes up automatically. The nflow editor's Run button fires the same stopFcn. A failing callback warns instead of aborting the completed run.

💡Examples
Run a self-contained demo and read back the logged signal
model = [modulepath('nflow_blocks'), '/examples/workspace/To_Workspace_Demo.nflow'];
out = sim(model, 'StopTime', 5);
plot(out.simout.time, out.simout.signals.values);
Feed a From Workspace block from the base workspace
t = (0:0.01:10)';
simin = [t, sin(2*pi*0.5*t)];
out = sim([modulepath('nflow_blocks'), '/examples/workspace/From_Workspace_Demo.nflow']);
🔗See Also
load_systemnew_systemfromWorkspacetoWorkspaceNFlow.plotScopes
🕔Version History
Version Description
1.0.0 initial version
Edit this page on GitHub