MATLAB: Does converting a multiple port S-parameters to Verilog-A module give me an error

rationalfitRF Toolboxverilog-awriteva

I have a multi-port S parameters file, and I want to convert is into Verilog-A module using the rational function object. 
My Touchstone filename is 'tmp.s55p' (for a 55 port network), and I execute the following MATLAB code – 
*
*>> sp = sparameters('tmp.s55p')
sp =
sparameters: S-parameters object
NumPorts: 55
Frequencies: [217×1 double]
Parameters: [55×55×217 double]
Impedance: 50
>> freq = sp.Frequencies;
>> param = sp.Parameters;
>> fit = rationalfit(freq,param)
Warning: Achieved only -18.1 dB accuracy with 48 poles, not -40.0 dB. Consider specifying a larger number of poles using the 'NPoles' parameter.
> In rationalfitcore
In rationalfit (line 112)
fit =
55x55 rfmodel.rational array with properties:
A
C
D
Delay
Name
>> status = writeva(fit, 'tmp')
Error: rfmodel.rational/checkproperty (line 17)
The first input argument rfmodel.rational must be a scalar.
Error: rfmodel.rational/writeva (line 81)
checkproperty(h);

Best Answer

With 55-port input data, the value returned by 'rationalfit' is a 55x55 array of fit objects.  As shown in the error message above, the first input argument of 'writeva' must be a scalar, not a 55x55 array.
The solution is to loop through the elements of the fit array by indexing fit(i,j), for example.:
 
>> status = writeva(fit(1,1),'tmp')
status =
logical