Not limited to subs, the same principle was also used on ships via degaussing coils: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Degaussing" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Degaussing</a>