How to take out a range of values from matrices within a cell with a for loop?

조회 수: 2 (최근 30일)
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
Nikolay N Valov
Nikolay N Valov 2018년 6월 26일
So each array that is stored in the cells needs to go from 600:4000. However, there are 3 arrays in the cell that are only 1000 long so I would not be using them.
I gave a general example in the question because if someone provides an answer I can fix those values myself.
OCDER
OCDER 2018년 6월 26일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2018년 6월 26일
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
OCDER
OCDER 2018년 6월 26일
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);
Nikolay N Valov
Nikolay N Valov 2018년 6월 27일
Thanks to both you! It was exactly what I needed for this.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by