Extracting certain data from multiple column vectors

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?

 Respuesta aceptada

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 comentarios

How can I put them into a cell array when the length of each vector varies? and some quite drastically
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 25 de Sept. de 2015

Comentada:

el 25 de Sept. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by