How to create separate tables from a data set
Afficher commentaires plus anciens
Working with gait analysis data, the exported raw file separates the data into four "tables" on top of each other (Joints, Model outputs, Segments and Trajectories).
When I use the readtable function, it identifies the variables from the top table (Joints) but not the other tables and instead has 5 rows of NaN separating the tables.
How do I get my code to identify and separate the data into easier to read tables.
(Attached is the file as a .txt, the file was too large to attach as .csv which is what I've been working with)
3 commentaires
dpb
le 10 Fév 2021
How about cutting the file size down to just a few lines of each section and (say) a half-dozen variables so folks can see what the organization is that you know about?
The size won't make any difference to the code but would make understanding the problem much simpler for folks here...
Jak
le 10 Fév 2021
Image Analyst
le 10 Fév 2021
Please explain what column numbers of that are supposed to be what table. And do you want an array of tables (one table for each patient) or do you want all patients in the same table with the patient ID as one of the columns (so there is just a single set of 4 tables)?
Réponse acceptée
Plus de réponses (1)
Mathieu NOE
le 10 Fév 2021
hello
here below my suggestion to split the large csv file into smaller txt files
they may be smarter use of regexp but this is what I can offer quick and dirty
seems you can now easily do a second loop to load these files with readtable and generate your multiples tables from there;
hope it helps, even if it can certainly be further refined
% Tell it what folder you want to put the files in
outdir = cd;
% Read the initial file in all at once
filename = 'Level Reduced.csv';
fid = fopen(filename, 'r');
data = fread(fid, '*char').';
fclose(fid);
% Break it into pieces based upon ',,,,,,,,,,,,,,,,,,,,,,,,' lines
pieces = regexp(data, '\n\s*\n', 'split');
[match,piece,startIndex,endIndex] = regexp(data,',,,,,,,,,,,,,,,,,,,,,,,,','match','split');
% Now loop through and save each one
n = 0;
for k = 1:numel(piece)
if size(piece{k},2) > 100 % so avoid storing empty files or single line (title)
n = n + 1;
filename = fullfile(outdir, ['out' num2str(n), '.txt']);
% Now write the piece to the file
fid = fopen(filename, 'w');
fwrite(fid, piece{k});
fclose(fid);
end
end
1 commentaire
Mathieu NOE
le 10 Fév 2021
just noticed this line has to be removed :
pieces = regexp(data, '\n\s*\n', 'split');
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!