Process s3p touchstone txt file without RF toolbox

Hello,
I would appreicate any suggestions on how to process a .s3p touchstone file without using RF toolbox
What i am trying to do is read the .txt file and re-arrange the data such that I have total of 19 coloums so that they are arranged with repsect to the frequency measured.
For example:
I am looking to re-arrange the below data
!S3P File: Measurements: <S11,S12,S13>,
!<S21,S22,S23>,
!<S31,S32,S33>:
# Hz S dB R 50
10000000 -0.0092246765 0.1925537 -83.385567 139.40034 -90.755653 -137.22295
-96.67411 118.48376 -38.536278 49.418709 -200 45
-80.850029 151.7863 -200 45 -17.785948 -121.2715
109950000 -0.0015148522 -0.36911103 -81.171486 10.863544 -102.95087 117.87647
-79.468361 87.581718 -35.982349 29.959129 -200 45
-97.319443 24.15667 -200 45 -21.274569 91.166023
to
!S3P File: Measurements: <S11,S12,S13>,
!<S21,S22,S23>,
!<S31,S32,S33>:
# Hz S dB R 50
10000000 -0.009 0.192 -83.385 139.400 -90.755 -137.222 -96.674 118.483 -38.536 49.418 -200 45 -80.850 151.789 -200 45 -17.785 -121.271
109950000 -0.001 -0.369 -81.171 10.863 -102.950 117.876 -79.468 87.581 -35.982 29.959 -200 45 -97.319 24.156 -200 45 -21.274 91.166
Any suggestions or examples are much appreciated.
Thank you,
KAS14

3 Comments

Please attach a sample .sp3 file -- because spacing is important for this matter.
When you truncate to 3 digits, are you wanting to round() or floor() or ceil() or fix() ? You have some negative values, so the difference between floor() and fix() is important for this purpose.
Thank you Walter for your response.
Attached is the example. In actuality i am not looking to truncate any values. I just did that to reperesent all data in one line in this text editor box as much as I could for representational purposes.
I am looking for any suggestion that would allow me to read the 18 values corresponsing to the frequency at which it was measured in one line with " " spacing so that i can easily use readtable to extract the s11,s12..s33 values easily.
I was looking into the possiblity of using fgetl but would help to see a example to better understand how to use it
Regards,
Kishen
I suggest you consider using textscan() with HeaderLines 15 and format repmat('%g', 1, 19)
If the number of header lines is not consistent you might need to work with the 'Comments' option
If working with the Comments option gets too tricky then fileread() the entire file, then regexprep() to replace
'^(!|#).*$'
with '' (empty character vector), and textscan() the rest.

Sign in to comment.

Answers (0)

Asked:

on 11 Aug 2023

Commented:

on 14 Aug 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!