Basically, I'm looking for a generalization of flipud
and fliplr
to flip the i-th dimension of an nd-array.
When the dimension to be flipped is the first one, I guess I can use
function flipped = flipfirst(ndarr)
sz = size(ndarr);
flipped = reshape(flipud(reshape(ndarr, sz(1), [])), sz);
end
Likewise, if the dimension to be flipped is the last one, I could use
function flipped = fliplast(ndarr)
sz = size(ndarr);
flipped = reshape(fliplr(reshape(ndarr, [], sz(end))), sz);
end
I'm sure that I can code something more general, with calls to permute
and whatnot, but is there anything built-in for this?
I'm not sure how expensive it is to do all the reshape
-ing above, but if it is, I'd also be interested in more efficient non-built-in approaches.