MATLAB Answers

Read data file with mixed delimited columns

1 view (last 30 days)
Georgios on 15 Jan 2018
Commented: Georgios on 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

Accepted Answer

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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!