Is there a built-in way to flip the ith size of an n-array?

Basically, I'm looking for compilation flipudand fliplrtranslation of i-nd-array measurements.

When the dimension to be flipped is the first, I guess I can use

function flipped = flipfirst(ndarr)
    sz = size(ndarr);
    flipped = reshape(flipud(reshape(ndarr, sz(1), [])), sz);
end

Similarly, if the dimension to be flipped is the last, I could use

function flipped = fliplast(ndarr)
    sz = size(ndarr);
    flipped = reshape(fliplr(reshape(ndarr, [], sz(end))), sz);
end

I'm sure I can code something more general, with calls permuteand something else, but is there anything for this?

I'm not sure how expensive it is to do all the reshapeabove, but if so, I will also be interested in more efficient non-built approaches.

+3
source share
2 answers

R2013b +, new flip:

A = rand(2,2,2);
B = flip(A,3);

flipdim:

A = rand(2,2,2);
B = flipdim(A,3);

edit flipdim , flipdim.

+7
+4

All Articles