From: us on
"Jarodd Holmes" <lapaipishki(a)googlemail.com> wrote in message <i3ic4o$25e$1(a)fred.mathworks.com>...
> Dear fellow Matlab users,
>
> I am trying to solve the following problem:
>
> I have a cell array with 500 cells, each cells contains 4 arrays with information (it is basically a cell array and each cell contains a matrix with four columns (column 1, column 2, column 3 and column 4) and 100 lines). I want to use cellfun and make matlab go into each cell and reorder the column order, so that the new cell array has the same number of cells and the same matrix, except that the order of the columns should be (column 1, column 3, column 2, column 4).
> If I didn't have a cell array and only one matrix X, i would just use this command:
> newX = [x(:,1) x(:,3) x(:,2) x(:,4)]. However with a cell array I cannot seem to make the proper usage of the cellfun command.
> I tried this one:
> newreturns=cellfun(@(x) [x(:,1) x(:,3) x(:,2) x(:,4)],returns, 'uni',false)
> but it does not work... could you please tell me where is my mistake? I just don't know how to define "all cells" and I am sure that the mistake is after the @(x) part, but I don't know how to fix it.
>
> All input greatly appreciated!
>
> Best Regards!

one of the possible solutions
- if i understand you correctly...

c={
1:4
5:8
9:12
};
r=cat(1,c{:})
%{
% r =
1 2 3 4
5 6 7 8
9 10 11 12
%}

us