Extracting certain data from multiple column vectors

9 views (last 30 days)
So I have 50 different 1 column vectors that I need to extract certain data from each vector. I need to define a new vector when t(i+1) < t(i). So there is one drop in my vector and I need to be able to find it, then create a new vector with only the information from that point until the end of the vector without overwriting the other vector. Each of the 50 vectors I have all have a different number of rows and this drop point of my data all happens in a different spot too. How do I write a for/if loop to find this new set of data?

Accepted Answer

Walter Roberson
Walter Roberson on 25 Sep 2015
splitVec = @(V) mat2cell(V(:), diff([0; find(diff(V(:))<0); length(V)]), 1);
If your 50 vectors are in a cell array, say V50, then you can
cellfun(splitVec, V50, 'Uniform', 0)
  2 Comments
Kristen Brusich
Kristen Brusich on 25 Sep 2015
How can I put them into a cell array when the length of each vector varies? and some quite drastically
Walter Roberson
Walter Roberson on 25 Sep 2015
V50 = {first_vector, second_vector, third_vector, ...}
cell arrays are not like numeric arrays. In cell arrays the size and data type of the cell elements can vary between elements. For any one element such as V50{17} it would be a particular numeric array whose size did not depend upon anything else in V50
V50 = {1:3, uint8(1:21), rand(1,10000), 'hello', ones(7,19)};
Different number of values in each element and different datatypes for each element. V50{4} would return the 'hello' string for example, but V50{3} would be the double precision row vector of length 10000.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices 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!