Short Version
How can I do concatMap
in MATLAB? I'm trying to build a single vector from a series of smaller, differently sized vectors. I know I can do:
result = [];
for i=1:N
result = [result nextPart(i)];
end
but that has a serious speed impact and there must be a smarter way to do concatMap
.
Long Version
I'm trying to write a MATLAB function that returns the counterdiagonals of a block. For example, if you have the block:
1 2 4
3 5 7
6 8 9
then counterDiagonals(block)
should return [1 2 3 4 5 6 7 8 9]
.
I have a function that will find a single counter diagonal of a block. i.e. counterDiagonal(x, 3)
will return [4 5 6]
.
Therefore, counterDiagonals
should be as simple as concatMap counterDiagonal(x, i) (1:N)
where N
is (2*length(block)-1)
. How can I do this in MATLAB in an efficient way?