Segmenting a large data set into a subset then sequencing the subset
Show older comments
Dear Matlab Answers!
I have a segmentation problem within Matlab.
I’ve imported using swallow_csv (which is amazing) a large sequenced data set. The dataset is imported as a variable called numbers which is a 44320x102 double.
Now I can already produce a new variable called rowsGrasp which is a subset of numbers which puts the whole lines into the new variable when a grasp is detected (column 11. Either 0 or 1).
This is achieved with : rowsGrasp = numbers(numbers( :,11) == 1, :);
What I would like to do is from numbers produce a new variable (graspReleaseSequence) which takes the first row instance of grasp ( so the 11th column value is 1) in the numbers variable all the way down to the last row instance of grasp where the value is 1.
With this new variable what I would like to do is to add another column which sequences from 1 onwards when the grasp value changes. So if the first 6 rows of graspReleaseSequence’s grasp value = 1 then the new column (called sequenceNumber is 1) when the row with grasp type = 0 starts the sequenceNumber value would be 2 (say for 8 rows) until the row with grasp = 1 then it switches to sequenceNumber 3. And so on until the bottom of the variable.
What would be the best way of doing this?
Any pointers would be gladly appreciated!
Thanks,
Peter
2 Comments
Peter Snow
on 21 Jun 2017
"I'm thinking this might be easier to do in python then import it into Matlab!"
Really? Why would that be easier?
What would help us most to help you is when you provide a complete set of example input and output data (this does not need to be the real data, just something with the same properties): then we can test our answer code and show that it does what you want.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!
