splitting a .txt or .xlsx into separate data sets
2 views (last 30 days)
Show older comments
Andrew Dickins
on 19 Nov 2019
Edited: Matthew Thomas
on 24 Jan 2020
I have a set of data output from Polyworks that's essentiall miltiple line profiles and I'm looking for a way to automated separating them to save time as I run through multiple sets of data
the data sets are put out in this format as a .txt
# dataset 1 - 0
x1,y1,z1
x2,y2,z2
x3,y2,z2
# dataset 1 - 1
x4,y4,z4
x5,y5,z5
# dataset 1 - 2
x6,y6,z6
# dataset 2 - 0
x1,y1,z1
x2,y2,z2
in this case there's 2 data sets, however the data sets are split into subsets, eq 1 - 0, 1 - 1, 1 - 2
x y and z are positional values
each set starts with a '- 0' and the other nnumbers I just want the rows deleting so the file would look more like this:
# dataset 1 - 0
x1,y1,z1
x2,y2,z2
x3,y2,z2
x4,y4,z4
x5,y5,z5
x6,y6,z6
# dataset 2 - 0
x1,y1,z1
x2,y2,z2
following that I'd like the different datasets to be split into separate files so I can process them all individually and compare them
the amount of "sub" sets for each dataset is incosistent but they always start at - 0 and for addition reference the dataset names are actually more like "# AMSA4 combined - Cloud - clean.txt -meas- (13) - 0" for example
I'm sure there's a simple solution to this but I've not been able to find anything helpful from searching
0 Comments
Accepted Answer
Matthew Thomas
on 19 Nov 2019
Edited: Matthew Thomas
on 24 Jan 2020
I've attatched a function I've written that should help you with this. It will go through the text file and produce new text files named 1.txt, 2.txt, 3.txt .. etc for each "dataset", where the subset markers have been removed. It might need some minor editing to work for your specific case, but hopefully this will get you most of the way there.
It doesn't actually "load" the datasets as numbers at any point, as it sounds like you know how to do that already once they have been seperated out and cleaned up. If you aren't quite sure, look into the function textscan.
0 Comments
More Answers (0)
See Also
Categories
Find more on Workspace Variables and MAT-Files 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!