How to take out a range of values from matrices within a cell with a for loop?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nikolay N Valov
el 26 de Jun. de 2018
Comentada: Nikolay N Valov
el 27 de Jun. de 2018
My issue is that I have uneven matrices/vectors which I have put into a cell. I need to manipulate this data starting from a specific point. Therefore, I need to cut out the first few points and the last few to get the information that I need. I know how to do this manually, but that's just a hassle so I was wondering if there was a way to make it a for loop?
My data within the cell that I have attached is anywhere from 4500x1 to 4800x1 matrices and need to basically take out all of these matrices and make a similar cell that contains the first few hundred points taken out and the last few hundred taken out to make all of the arrays in the cells be around 3400x1 lets say.
3 comentarios
OCDER
el 26 de Jun. de 2018
What about sequences that are 3400 long? Do you extract 1:3400 then, since there are no 600:4000? By the way, 600:4000 would give you 3401 elements. Did you want 601:4000?
Respuesta aceptada
Guillaume
el 26 de Jun. de 2018
I gave a general example in the question because if someone provides an answer I can fix those values myself
Yes, but there are many ways of cropping arrays depending on the need. So our answer may not be adapted at all to what you really want.
However, there are 3 arrays in the cell that are only 1000 long so I would not be using them
yourcellarray(cellfun(@numel, yourcellarray) < 3400) = []; %remove cells which contain arrays of less than 3400 elements
Assuming you want to crop the remaining arrays to 3400 elements, removing elements from the start:
newcellarray = cellfun(@(arr) arr(end-3399:end), yourcellarray, 'UniformOutput', false);
2 comentarios
OCDER
el 26 de Jun. de 2018
A variation of @Guillaume's answer if you want to preserve the original data cell:
% Y is your cell array
N = cellfun(@(x) x(end-3399:end), Y(cellfun(@numel, Y)>=3400), 'un', 0);
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!