There are multiple ways:
https://www.mathworks.com/products/instrument/supported/keysight.html gives several examples. You can achieve automatic S parameter measurement using matlab
Keysight also offers a pre-installed matlab control: https://www.keysight.com/us/en/product/N6171A/matlab-software.html