Based on your question I think the first part of laptop2d's answer is what you need. Still, it can be improved a bit, at the cost of slightly more complications. It involves two rules.
a) in LTspice, grounding every pin of an element disables it (except current sources and subcircuits), and this is not limited to 2 pins elements only; transitors, switches, etc, are also disabled.
b) nodes' names are treated as labels, but can also be evaluated. For example, a net name x1
will be treated as a label, but can't be evaluated, while 0
and 00
will be treated as two, distinct nodes, but they both evaluate to zero (GND
).
Combining the two rules above, you can label a node in such a way that it evaluates to anything but zero, if you need the element between the nodes active, or to zero if you want it disabled. Example:
I1 23 0 1
R1 23 0 1
R2 {x} 0 1
.step param x list 0 23
This netlist will be run twice, for x=0
and x=23
, with R2
being disabled at first, and then enabled. Plotting V(23)
will show 1V
, then 0.5V
. The same result can also be achieved using
R2 {23*x} 0 1
.step param list 0 1
or
R2 {x-23} 0 1
.step param x list 23 0
or any other way that results in the same outcome, because whatever expression is within the accolades will be evaluated. Be sure to make the result of the evaluation 0
, not -0
, or it will count as a different label.
But LTspice doesn't allow naming the nets with accolades, at least not from within the GUI. Pressing F4
and explicitly writing {23}
will not be allowed due to illegal characters. This means that R2
needs to be added to the schematic via a SPICE directive (S
). This is where it gets a bit awkward, because if you have a fair number of elements, you'll have to do a bit of typing, not to mention choose proper expressions for every node, while making the schematic less readable.
These make more sense when working with subcircuits, where you want to enable/disable elements such that the matrix solver only counts the ones you need for the current simulation, but it can be done, just as well, in a normal schematic, such as yours.