MATLAB: Select specific values inside a cell

arraycellvalues

Hi,
I have a cell array that is 4×6. Inside each cell I have 1×31 values.
I would like to access in each cell just the last value. At the end I want a matrix that is 4×6.
Could you please help me with it?

Best Answer

%Just making a demo cell array
A = cell(4,6);
for j = 1:numel(A)
A{j} = randi(100, 1, 31);
end
%Use for small sizes like 4x6 cell array
C = cellfun(@(x) x(end), A);
%Use for large sizes like 100x600 cell array
B = zeros(size(A));
for j = 1:numel(A)
B(j) = A{j}(end);
end