How to import a csv file with multiple headers and variable data leghts between headers
10 views (last 30 days)
Show older comments
opts = detectImportOptions('WTXTest.csv')
g_clean_table = readtable('WTXTest.csv',opts);
index_crystal = find(strcmp('crystal',g_clean_table));
Hi I have to work with some huge output files, These files are formated in bash and then I want to put them in matlab so I can analyse the data, like energy per angle and ect...
the .csv file looks like this:
G4Track,Information:,Particle,=,gamma,Track,ID,=,1,Parent,ID,=,0
Step#,X(mm),Y(mm),Z(mm),KinE(MeV),dE(MeV),StepLeng,TrackLeng,NextVolume,ProcName
0,0,645,0,0.045,0,0,0,World,initStep
1,-6.48,200,-9.05,0.045,0,445,445,Patient,Transportation
2,-7.1,157,-9.91,0.0447,0,42.7,488,Patient,compt
3,-16,130,-16.9,0.0416,0,29.4,517,Patient,compt
4,53.7,85.7,15.5,0.0367,0,88.7,606,Patient,compt
5,48.7,100,18.3,0.0335,0,15.4,621,Patient,compt
6,82.3,87.1,54.8,0.0334,6.86e-05,51.2,673,Patient,compt
7,88.6,84.3,59,0.0309,0,8.04,681,Patient,compt
8,89.9,89.1,57.4,0.0309,0,5.21,686,Patient,Rayl
9,86.4,81.9,64,0,4.34e-05,10.3,696,Patient,phot
G4Track,Information:,Particle,=,e-,Track,ID,=,8,Parent,ID,=,1
Step#,X(mm),Y(mm),Z(mm),KinE(MeV),dE(MeV),StepLeng,TrackLeng,NextVolume,ProcName
0,86.4,81.9,64,0.000494,0,0,0,Patient,initStep
1,86.4,81.9,64,0,0.000494,2.23e-05,2.23e-05,Patient,eIoni
G4Track,Information:,Particle,=,e-,Track,ID,=,7,Parent,ID,=,1
Step#,X(mm),Y(mm),Z(mm),KinE(MeV),dE(MeV),StepLeng,TrackLeng,NextVolume,ProcName
0,86.4,81.9,64,0.0303,0,0,0,Patient,initStep
1,86.4,81.9,64,0,0.0303,0.018,0.018,Patient,eIoni
G4Track,Information:,Particle,=,e-,Track,ID,=,6,Parent,ID,=,1
Step#,X(mm),Y(mm),Z(mm),KinE(MeV),dE(MeV),StepLeng,TrackLeng,NextVolume,ProcName
0,88.6,84.3,59,0.00258,0,0,0,Patient,initStep
1,88.6,84.3,59,0,0.00258,0.000254,0.000254,Patient,eIoni
G4Track,Information:,Particle,=,e-,Track,ID,=,5,Parent,ID,=,1
Step#,X(mm),Y(mm),Z(mm),KinE(MeV),dE(MeV),StepLeng,TrackLeng,NextVolume,ProcName
0,48.7,100,18.3,0.00316,0,0,0,Patient,initStep
1,48.7,100,18.3,0,0.00316,0.000356,0.000356,Patient,eIoni
Note that the lenght between the two headers always change, how can I work with that? like getting to look for a specific process in the file and then work with it
0 Comments
Answers (1)
Mario Malic
on 26 Jul 2020
Edited: Mario Malic
on 26 Jul 2020
C = table2array((g_clean_table(:,1))); % Convert the rows of the first column into an array
x = find(C>=0) % this removes nan
x is a vector that contains the rows where the data in your table is stored.
g_clean_table(x,:)
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!