Read data file with mixed delimited columns

1 次查看(过去 30 天)
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

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Optimization 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by