MATLAB: Accessing columns of array elements in a cell array without for loops

cell arraysfor loopsindexing

I have a K-element cell array C1. Each element is an Nx3 array of doubles. How can I get a new cell array whose elements are the first column of each array in C1 using only logical indexing? For example, if C1 is {M1 M2 M3}, where M1=[1 2 3; 4 5 6; 7 8 9]=M2=M3; then I want a new cell array C2 that is {N1 N2 N3} where N1=[1;4;7]=N2=N3.
*Edit: My mistake, the K matrices do not all have the same number of rows (but they do all have 3 columns). See my comment below.
I can do this with a for loop:
for j=1:length(C1)
mat=C1{j}(:,1);
C2{j}=mat;
end
How can I do it without a loop?

Best Answer

C2 = cellfun(@(x)x(:,1),C1,'UniformOutput',false);