Compact way to horizontally concatenate a cell array without the first columns of the cells
Show older comments
Hi, I have two matrices A and B that are "stored" inside a cell array C.
Just manipulating the cell array C (and not matrices A and B), I would like to horizontally concatenate the two cells of C in a compact way, with the condition of not taking the first column of both cells.
Here my example:
% input
A = [2 4 6
1 3 8
6 9 1
6 1 1
5 5 2
3 7 8
9 2 4]
B = [8 3 5
9 9 5
6 3 1
7 1 2
4 8 7
2 2 4
5 7 3]
% creation of the cell array C
C{1} = A;
C{2} = B;
% horizontal concatenation of the C's cells
D = horzcat(C{:})
% result - just using horzcat(C{:}), the first columns of A and B are present
D =
2 4 6 8 3 5
1 3 8 9 9 5
6 9 1 6 3 1
6 1 1 7 1 2
5 5 2 4 8 7
3 7 8 2 2 4
9 2 4 5 7 3
% desired output - where the first columns of A and B are absent
D =
4 6 3 5
3 8 9 5
9 1 3 1
1 1 1 2
5 2 8 7
7 8 2 4
2 4 7 3
% Note: the following naive attempt gives me an error
>> horzcat(C{:}(:,2:3))
Expected one output from a curly brace or dot indexing expression, but there were 2 results.
Is there any compact way to get my desired output,
- just manipulating C (and not A and B) and
- possibly still using horzcat (or similar built-in functions), like/similarly to horzcat(C{:}) ?
Accepted Answer
More Answers (0)
Categories
Find more on Cell 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!