File Exchange Pick of the Week

Our best user submissions

Flip Arrays

Note

The file submission referenced in this post is no longer available on File Exchange.


I love small, simple, useful functions. Many of my own submissions are not much more than one line of code (wopen, goto) that I use dozens of times a week. Duane Hanselman submitted a great one the other day. FLIPARRAY works just like FLIPUD and FLIPLR, except that it doesn’t require you to figure out if the input is a row or column vector first. It also extends nicely to support multidimensional arrays, preserving the array shape.

Duane received some grief over such a “simple” submission, including a nomination for removal. I couldn’t disagree more – I think submissions like this make the File Exchange great, and make MATLAB much more enjoyable to live with. The fact that it’s only one line of code tells me two things:

  1. MATLAB has a very compact, efficient language.
  2. Duane knows how to use it to his advantage.

I don’t know about you, but I’d much rather type:

>> x = fliparray(x)

than

>> x(:)=x(end:-1:1); 

It takes less thought, is easier to type, and makes my code infinitely more readable. Thanks, Duane.

|
  • print
  • send email

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.