I want to read ascii file into matlab which has 191 rows and 9 columns. Then I have to convert it into matrix form that too row wise also I have to convert magnitude and angle into real and imaginary parts.

The data below is in 9 columns. The first column is for frequency, which is in hertz. The second column is for S11 magnitude, the third for S11 angle, the 4th column is S12 magnitude, the 5th is S12 angle and so on. All eight columns are S-parameters which are in magnitude and angle and I have to take them row by row, and read this data directly into matlab, and then form a matrix. Then I have to convert it into real and imaginary parts.
. # Hz S MA R 50
row 1 : 1000000000.000 +9.8103468350E-001 -1.1212773233E+001 +7.5138900895E-002 +6.7503685995E+001 +7.5911915353E-002 +7.7612286233E+001 +6.6197497335E-001 -5.5698989097E+000
row 2 : 1100000000.000 +9.7789664654E-001 -1.2343173752E+001 +8.2372076274E-002 +6.7164745132E+001 +8.3032257289E-002 +7.6655276053E+001 +6.6534801460E-001 -6.0731137365E+000
row 3 : 1200000000.000 +9.7414597496E-001 -1.3450479844E+001 +8.9137342173E-002 +6.6984995092E+001 +9.0037093048E-002 +7.5847505505E+001 +6.6377100820E-001 -6.7338426347E+000
row 4 : 1300000000.000 +9.7079182625E-001 -1.4524257360E+001 +9.6368252287E-002 +6.6520385977E+001 +9.7232350444E-002 +7.4786965364E+001 +6.6260679152E-001 -7.1749452934E+000
row 5 : 1400000000.000 +9.6708627191E-001 -1.5607081020E+001 +1.0320309179E-001 +6.6173275207E+001 +1.0372396159E-001 +7.3691071630E+001 +6.6218596876E-001 -7.6584585544E+000
row 6 : 1500000000.000 +9.6345447413E-001 -1.6659061335E+001 +1.0998283042E-001 +6.5718349968E+001 +1.1088458742E-001 +7.2508135318E+001 +6.6157989011E-001 -8.1416809458E+000
row 7 : 1600000000.000 +9.5914548536E-001 -1.7737862984E+001 +1.1668774834E-001 +6.5174792956E+001 +1.1751354475E-001 +7.1622743616E+001 +6.6018222718E-001 -8.6633952654E+000

 Réponse acceptée

To read the ASCII file into Matlab:
doc textscan
To convert from magnitude-angle to complex a+bj, just use
Complex= Magnitude.*exp(j*Angle);

10 commentaires

where should i mention the file name or file path..and also i have to convert first roe into matrix form
Did you read the text, which appears when you type "doc textread" in the command line already?
Ria, I'm confused by the format of the file. Does "row 1", "row 2", etc. actually appear in the file, or did you add those just to indicate to us where the row breaks are located? Can you paste the first seven rows of the file as it appears in the actual file for us?
Also, the documentation for textscan clearly indicates where to specify the file name. Read it!
@Matt Kindig : sir file name is : C1_vd0_vg-5.S2P ; S2P stands for Scattering parameters.and the first row has 9 elements ;first element indicates frequency ;second column indicates S11 magnitude parameter ,third column indicates S12 mag ,4th S12 angle ; and then for S21 ,S22...and they are written in a notepad.there is no excel file. and I have to first read the file and then I have print row by row in Matrix form in Editor window of MATLAB.and on each row I have to perform some operations.PLEASE reply soon .also , text scan,textread, load ,nothing is working.
*FIRST SEVEN LINES OF THE FILE *:please cut and paste in your notepad to get the exact view of the file:
! 2-Port S-parameters saved by WinCal ! VAR MeasName=S-Parameters (CALIBRATED_DATA) read from VNA (N5244A) ! VAR MeasDate=7/10/2012 12:51:24 PM ! VAR NAME=Measurement 8 ! VAR FILENAME=C1_vd0_vg-5.S2P ! VAR DATE=7/10/2012 12:51:24 PM ! VAR PHYS_PORTS=1,2 ! # Hz S MA R 50 1000000000.000 +9.8103468350E-001 -1.1212773233E+001 +7.5138900895E-002 +6.7503685995E+001 +7.5911915353E-002 +7.7612286233E+001 +6.6197497335E-001 -5.5698989097E+000 1100000000.000 +9.7789664654E-001 -1.2343173752E+001 +8.2372076274E-002 +6.7164745132E+001 +8.3032257289E-002 +7.6655276053E+001 +6.6534801460E-001 -6.0731137365E+000 1200000000.000 +9.7414597496E-001 -1.3450479844E+001 +8.9137342173E-002 +6.6984995092E+001 +9.0037093048E-002 +7.5847505505E+001 +6.6377100820E-001 -6.7338426347E+000 1300000000.000 +9.7079182625E-001 -1.4524257360E+001 +9.6368252287E-002 +6.6520385977E+001 +9.7232350444E-002 +7.4786965364E+001 +6.6260679152E-001 -7.1749452934E+000 1400000000.000 +9.6708627191E-001 -1.5607081020E+001 +1.0320309179E-001 +6.6173275207E+001 +1.0372396159E-001 +7.3691071630E+001 +6.6218596876E-001 -7.6584585544E+000 1500000000.000 +9.6345447413E-001 -1.6659061335E+001 +1.0998283042E-001 +6.5718349968E+001 +1.1088458742E-001 +7.2508135318E+001 +6.6157989011E-001 -8.1416809458E+000 1600000000.000 +9.5914548536E-001 -1.7737862984E+001 +1.1668774834E-001 +6.5174792956E+001 +1.1751354475E-001 +7.1622743616E+001 +6.6018222718E-001 -8.6633952654E+000 1700000000.000 +9.5591877038E-001 -1.8743901494E+001 +1.2267810014E-001 +6.4622596128E+001 +1.2439050594E-001 +7.0611719417E+001 +6.5758257710E-001 -9.1045944719E+000
EXACT VIEW
! 2-Port S-parameters saved by WinCal
! VAR MeasName=S-Parameters (CALIBRATED_DATA) read from VNA (N5244A)
! VAR MeasDate=7/10/2012 12:51:24 PM ! VAR NAME=Measurement 8
! VAR FILENAME=C1_vd0_vg-5.S2P ! VAR DATE=7/10/2012 12:51:24 PM
! VAR PHYS_PORTS=1,2
! # Hz S MA R 50
1000000000.000 +9.8103468350E-001 -1.1212773233E+001 +7.5138900895E-002 +6.7503685995E+001 +7.5911915353E-002 +7.7612286233E+001 +6.6197497335E-001 -5.5698989097E+000
1100000000.000 +9.7789664654E-001 -1.2343173752E+001 +8.2372076274E-002 +6.7164745132E+001 +8.3032257289E-002 +7.6655276053E+001 +6.6534801460E-001 -6.0731137365E+000
1200000000.000 +9.7414597496E-001 -1.3450479844E+001 +8.9137342173E-002 +6.6984995092E+001 +9.0037093048E-002 +7.5847505505E+001 +6.6377100820E-001 -6.7338426347E+000
1300000000.000 +9.7079182625E-001 -1.4524257360E+001 +9.6368252287E-002 +6.6520385977E+001 +9.7232350444E-002 +7.4786965364E+001 +6.6260679152E-001 -7.1749452934E+000
1400000000.000 +9.6708627191E-001 -1.5607081020E+001 +1.0320309179E-001 +6.6173275207E+001 +1.0372396159E-001 +7.3691071630E+001 +6.6218596876E-001 -7.6584585544E+000
1500000000.000 +9.6345447413E-001 -1.6659061335E+001 +1.0998283042E-001 +6.5718349968E+001 +1.1088458742E-001 +7.2508135318E+001 +6.6157989011E-001 -8.1416809458E+000
1600000000.000 +9.5914548536E-001 -1.7737862984E+001 +1.1668774834E-001 +6.5174792956E+001 +1.1751354475E-001 +7.1622743616E+001 +6.6018222718E-001 -8.6633952654E+000
1700000000.000 +9.5591877038E-001 -1.8743901494E+001 +1.2267810014E-001 +6.4622596128E+001 +1.2439050594E-001 +7.0611719417E+001 +6.5758257710E-001 -9.1045944719E+000
Hz S MA R 50 means Hz :freq in hertz , S -s-parameters ,MA -magnitude angle , R - resistance is 50 ohms.
Then first row starts from :
1000000000.000 +9.8103468350E-001 -1.1212773233E+001 +7.5138900895E-002 +6.7503685995E+001 +7.5911915353E-002 +7.7612286233E+001 +6.6197497335E-001 -5.5698989097E+000
Ok, so here's some code that can help you:
str = fileread('YOUR_FILENAME_HERE'); %read in file
%remove lines that star with ! and #
str= regexprep( str, '^(!|#)([^\n]+)\n', '', 'LineAnchors');
num= str2num(str); %convert to numerical
frequency = num(:,1);
S11 = num(:,2);
%continue like this reading in all columns into variables
See my first comment to show how to do the conversion to complex numbers.
Also, one of the fundamental mistakes that you made with this forum is simply to say that "textscan, textread, load, nothing is working", without explaining what is not working about those functions. You should also post your code and what doesn't work. Simply saying that something "doesn't work" without telling us why not only makes it difficult for us to tell you in what way your code is incorrect (and thus helping you to improve your MATLAB skills for the future), but also demonstrates to us that you actually tried to solve your problem. For me (and perhaps other posters as well), I am suspicious when posters say "nothing is working", because it is an easy way to hide the fact that no actual effort was expended.
TEXTSCAN,TEXTREAD,LOAD all were not working because the file contain few comment lines. so I tried this code line after removing the comments.it is working now :
A = load ('filename') %read in file
size(A) %tells the size of the file i.e. 191x9
A(1,:) %prints the first row
A([1],[2 3 4 5 6 7 8 9])
s11mag = A(1,2) %it will assign the magnitude value
%and so on....
thank you sir for the information.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Export dans Centre d'aide et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by