Script to clear traces on the scope

I’ve made a model with a script to plot mulltiple trace in an ac analisys fro different value of an iunductor

ti works fine but it does not delete the previous trace on the scope, folloving the script and attached the PLECS model someone can show me where is the mistake?

second question how to modify the script to add grids on the graph?

% create simStruct with field ‘ModelVars’

mdlVars = struct(‘varL’, 5e-6);

simStruct = struct(‘ModelVars’, mdlVars);

plecs(‘scope’, ‘./Scope’, ‘ClearTraces’);

% parametric values to be swept

inductorValues = [2, 4, 6, 8, 10, 15]; % in uH

legendValues = {};

for ix = 1:length(inductorValues)

% set value for L1

simStruct.ModelVars.varL = inductorValues(ix) * 1e-6;

simResult=plecs(‘analyze’, ‘AC Sweep’, simStruct)

plecs(‘scope’, ‘./Analyses/AC Sweep’, ‘ClearTraces’);

legendStr = [‘L=’ mat2str(inductorValues(ix)) ‘uH’];

legendValues(ix) = legendStr;

% start simulation, return probed signal values to workspace using Output port ‘1’

% hold and label traces in Scope

plecs(‘scope’, ‘./Analyses/AC Sweep’, ‘HoldTrace’)

subplot(2,1,1);

semilogx(simResult.F,abs(simResult.Gr+1i*simResult.Gi));

hold on;

subplot(2,1,2);

semilogx(simResult.F,angle(simResult.Gr+1i*simResult.Gi)*180/pi);

hold on;

end

% Label plots

subplot(2,1,1);

title(‘Example of Bode Plot with Linear Magnitude’);

xlabel(‘Frequency (Hz)’);

ylabel(‘Magnitude’);

legend(legendValues);

subplot(2,1,2);

xlabel(‘Frequency (Hz)’);

ylabel(‘Phase (deg)’);

legend(legendValues);

input_stage_resonance.plecs (13 KB)

> ti works fine but it does not delete the previous trace on the scope,

When I ran your model only the last simulation result was shown in the AC sweep window. Perhaps you mean it is not holding the all the traces on the AC Sweep results scope? The reason you only see the last result is the order of your script. You are clearing the traces in your for loop, instead of just before you enter the loop.

If that’s not the case then a better description of your issue and desired outcomes would be necessary.

i’ve just cheked, it happens if i run again the script without closing the octave windows, in this case previous traces are not cleared if i close the octave windiws and i run agai the script, previost trace are cleared