Holding a Trace in the Scope

Hello fdegioanni,

In the demo-models, look for “Buck converter with parameter sweep”. There you find this in the simulation script:

% create simStruct with field 'ModelVars'
mdlVars = struct('varL', 50e-6);
simStruct = struct('ModelVars', mdlVars);

% clear all traces in scope 'Scope' in the current model
plecs('scope', './Scope', 'ClearTraces');

inductorValues = [50, 100, 200];
for ix = 1:length(inductorValues)
  % set value for L1
  simStruct.ModelVars.varL=inductorValues(ix) * 1e-6;
  % start simulation, return probed signal values in 'out'
  out = plecs('simulate', simStruct);
  % hold and label trace
  plecs('scope', './Scope', 'HoldTrace', ['L=' mat2str(inductorValues(ix)) 'μH']);
  % find maximum current value and index
  [maxv, maxidx] = max(out.Values(1,:));
  % Output maximum current values to Octave console
  printf('Max current for L=%dμH: %fA at %fs
',
          inductorValues(ix), maxv, out.Time(maxidx));
end

Where this example uses ‘./Scope’, use the name of your particular scope, for example ‘./MyScope’.

If your scope is an a subsystem, the path must be adapted accordingly, for example ‘./MySubsystem/MyScope’.

The path uses unix-like syntax, where the dot refers to the current location (or current model, in this context).