Read data file with mixed delimited columns

조회 수: 1 (최근 30일)
Georgios
Georgios 2018년 1월 15일
댓글: Georgios 2018년 1월 16일
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