rearranging the data in separate columns when difference of 10 is found in vectors
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
I have data like: 1,2,3,4,5,7,8,11,13,14,15,17,18,19,21,23,24...34..,
Here, I would like to divide this series into columns as soon as the difference of ten from the initial number is found in the vector. I.e: Column one will contain, 1,2,3,4,5,7,8,11 and Column 2 will 13,14,15,17,18,19,21,23, and third column the values from 24...34 and so forth.
The initial values changes relatively and starts at last break value. i.e. first relative value would be 1, second 13, third 24 and so on.
These can also be copied in independent matrices, say: A, B, C, D... and each contains vector whose first value and last value differ by 10. But, size of A,B,C,D... need not be identical.
Any hints or example code would be highly helpful.
1 comentario
Walter Roberson
el 11 de Feb. de 2012
duplicate is at http://www.mathworks.com/matlabcentral/answers/28116-rearranging-the-data-in-separate-columns-when-difference-of-10-is-found-in-vector
Respuestas (2)
Andrew Newell
el 11 de Feb. de 2012
You could do this using a cell array:
% preallocate array
n = ceil(max(x)/10);
y = cell(n,1);
% populate it
for ii=1:n
y{ii} = x(x>10*(ii-1) & x<=10*ii+1);
end
Andrei Bobrov
el 11 de Feb. de 2012
A - your vector (issorted(A) == 1)
n = A;
out = [];
while ~isempty(n)
k = (n - n(1)) <= 10;
out = [out;{n(k)}];
n = n(find(k,1,'last')+1:end);
end
La pregunta está cerrada.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!