exsonic01
exsonic01

Reputation: 637

gathering specific rows from each submatrices or cell arrays

I hope to gather last lines from each submatrix or cell arrays.

Upvotes: 1

Views: 424

Answers (1)

nicktruesdale
nicktruesdale

Reputation: 815

First off, it looks like you switched x_cc and y_cc. Since your matrix is 17 x 20, x_cc is the rows and should go to 17, while y_cc will go to 20.

However, the error you're getting is probably coming from trying to index an empty array (one of those contained in A) using end. An example of this error:

a = [];

a(end)
??? Subscript indices must either be real positive integers or logicals.

If you're curious, a method avoiding for loops would look like:

B = cellfun(@(x) x(end,:), A, 'UniformOutput', 0);  
M = cell2mat(B(:));

This grabs the last row from each matrix in A, then stacks them vertically and transforms to an array.

Upvotes: 2

Related Questions