필터 지우기
필터 지우기

How to read a column named by some header in data file?

조회 수: 16 (최근 30일)
prashant sharma
prashant sharma 2018년 11월 5일
댓글: madhan ravi 2018년 11월 5일
Dear All, I have 10 to 15 columns named with different headers in one data file (data.dat) (sample data file is attached below). The position of the column is not fixed and they can change after each run according to the inputs. Therefore, it is difficult to make a program with fixed column numbers. Is there any way to sort out the columns by their name and then proceed for other calculations? For example: Plot between Time and 2p2_3p1_4S___, multiplying any column by number (scalar), etc.
Time 2p2_3p1_4S___ 2p1_3p1_3D___ 2p1_3d1_4F___ 1s2_3p1_2P___
1.0000000E-07 1.387545E-011 8.116580E-008 6.224102E-006 1.804010E-006
2.0000000E-07 3.149958E-012 1.922005E-008 1.512518E-006 4.319076E-006
3.0000000E-07 2.180968E-012 1.353958E-008 1.076323E-006 6.377379E-006
4.0000000E-07 1.951598E-012 1.214133E-008 9.663528E-007 7.997309E-006
5.0000000E-07 1.805993E-012 1.124047E-008 8.948846E-007 9.263814E-006
6.0000000E-07 1.690790E-012 1.052642E-008 8.381780E-007 1.024948E-005
7.0000000E-07 1.597212E-012 9.946256E-009 7.920958E-007 1.101235E-005
8.0000000E-07 1.520693E-012 9.471772E-009 7.544044E-007 1.159861E-005
9.0000000E-07 1.457775E-012 9.081556E-009 7.234037E-007 1.204494E-005
1.0000000E-06 1.405719E-012 8.758646E-009 6.977473E-007 1.238051E-005
1.1000000E-06 1.362348E-012 8.489555E-009 6.763642E-007 1.262849E-005
1.2000000E-06 1.325931E-012 8.263553E-009 6.584026E-007 1.280729E-005
1.3000000E-06 1.295089E-012 8.072101E-009 6.431845E-007 1.293155E-005
1.4000000E-06 1.268726E-012 7.908405E-009 6.301705E-007 1.301287E-005
1.5000000E-06 1.245968E-012 7.767055E-009 6.189311E-007 1.306048E-005
1.6000000E-06 1.226121E-012 7.643745E-009 6.091243E-007 1.308170E-005
1.7000000E-06 1.208630E-012 7.535042E-009 6.004778E-007 1.308236E-005
1.8000000E-06 1.193055E-012 7.438214E-009 5.927743E-007 1.306706E-005
1.9000000E-06 1.179043E-012 7.351078E-009 5.858408E-007 1.303945E-005
2.0000000E-06 1.166313E-012 7.271897E-009 5.795392E-007 1.300244E-005
Your kind help will be highly appreciated. Thanks
  댓글 수: 3
prashant sharma
prashant sharma 2018년 11월 5일
Hi Stephen, I am using Matlab 8.3 (R2014a). Thanks
Stephen23
Stephen23 2018년 11월 5일
편집: Stephen23 2018년 11월 5일
Then readtable is your best option, and you can access the variables of the table using the header names.

댓글을 달려면 로그인하십시오.

채택된 답변

madhan ravi
madhan ravi 2018년 11월 5일
편집: madhan ravi 2018년 11월 5일
Use
T=readtable('data.txt');
T.Time %finds column header with Time
^^^^|______________________________________%denotes column header
T.x2p1_3d1_4F___ = T.x2p1_3d1_4F___ * 2;
why x in front of 2 see comment
Then how will I write a program which read the data file and then searches the header for 2p1_3d1_4F___
You don't have to , if you specify the header name it will do the work for you
  댓글 수: 6
prashant sharma
prashant sharma 2018년 11월 5일
Thank you very much for the help... @madhan @Guillaume
madhan ravi
madhan ravi 2018년 11월 5일
Anytime :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by