Hope to gather last rows from each submatrices

1 view (last 30 days)
I hope to gather last lines from each submatrix.
- I have 17 x 20 submatrices in matrix name A.
- Each submatrices have different number of lines, but same number of columns (total 7 columns, all)
- I tried to generate a file, made up of only last rows of each submatrices. My target file's from will be
M = [column1 column2 column3 column4 column5 column6 column7]
% made up of last rows of each submatrices, unknown number of
lines, 7 columns
- So I tried
for x_cc = 1:20
for y_cc = 1:17
M = A{x_cc, y_cc}(end,:);
end
end
- But it is not working, giving the error Subscript indices must either be real positive integers or logicals.
- Should I need to define the size first? What operation should be done? or what commands are useful? I tried cellfun, but not sure how can I use here.
- Need any help to solve this situation. Thanks~!
  5 Comments
Walter Roberson
Walter Roberson on 6 Nov 2012
Stack in what order? If your A is
P Q
R S
then do you want the last lines in the order
P
Q
R
S
or in the order
P
R
Q
S
exsonic
exsonic on 6 Nov 2012
Edited: exsonic on 6 Nov 2012
Order is not important, hope to just stack the last lines of each cell array of matrix.
I have
A =
[0x7 double] [10x7 double] [ 9x7 double]
[4x7 double] [ 5x7 double] [ 6x7 double]
....
Hope to choice only last lines from each arrays, and stack in the single matrix.
There are empty cells are exists, hope to just get 0 in that case.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 6 Nov 2012
AT = A(~cellfun(@isempty,A));
M = cellfun( @(C) C(end,:), AT);
  2 Comments
exsonic
exsonic on 6 Nov 2012
Great thanks~! I really need to study cellfun more~!
Walter Roberson
Walter Roberson on 6 Nov 2012
If you are certain of not having empty submatrices, you can reduce to
M = cellfun( @(C) C(end,:), A(:));

Sign in to comment.

More Answers (0)

Categories

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