Read data file with mixed delimited columns

1 Ansicht (letzte 30 Tage)
Georgios
Georgios am 15 Jan. 2018
Kommentiert: Georgios am 16 Jan. 2018
I have a file with data like this:
Freq. V(out)
1.000000000e-003 4.030864362e-004,2.007296583e-002
1.000693387e-003 4.036453944e-004,2.008687294e-002
1.001387255e-003 4.042051275e-004,2.010078967e-002
There are thousands of rows
I would like to have two columns, where the first column is the same as above but the second column is a complex number, made up of the two parts of the comma delimited part, like this:
1.000000000e-003 4.030864362e-004+2.007296583e-002i
1.000693387e-003 4.036453944e-004+2.008687294e-002i
1.001387255e-003 4.042051275e-004+2.010078967e-002i
I have been using a text editor to remove the first line header, and the comma, to create what I am looking for.
Below is an example of the code. The data is in a file named RC_HighPassCartesian.txt
load RC_HighPassCartesian.txt
w=RC_HighPassCartesian(:,1); % Copy first column into vector w
w=w*2*pi; % Convert to radians
h1=RC_HighPassCartesian(:,2); % Copy second column into vector h1
h2=RC_HighPassCartesian(:,3); % Copy third column into vector h2
h2=h2*1i; % Multiply h2 column by imaginary unit i
h=h1+h2; % Create h as a complex valued vector
Is there a more elegant and direct way to do this?
Regards, Georgios

Akzeptierte Antwort

Elias Gule
Elias Gule am 16 Jan. 2018
Please try the attached code. It's not elegant but it does what you want.
  1 Kommentar
Georgios
Georgios am 16 Jan. 2018
Thank you. It works. Qustion: Why do you add a zero valued imaginary component to the first column? It seems redundant.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Optimization finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by