File Exchange Pick of the Week

September 1st, 2005

Flip Arrays

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.

Comments are closed.


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Zach: Hi Doug and Les, I didn’t have a lot of time to mess with this, but I did find a work-around. I plotted...
  • hamed: k
  • Les: @Zach This isn’t exactly what you are looking for but at least it puts all three parameters on the same...
  • Zach: Thanks for your suggestions Doug. I’ll give that a shot and see what happens. I’ve seen many of...
  • Doug: @Zach, I would say to use plotYYY, because that is close to what you want, but using depth as Y makes sense....
  • Doug: @Teja, I think this will work: http://www.mathworks .com/access/helpdesk /help/techdoc/ref...
  • Gify: merry christmas :) nice christmas tree! Regards, Janet Gify
  • Teja: Dear Doug Is there anyway to plot a surface from nonuniform data without meshgrid and griddata? Basically i...
  • Zach: I’m working with geophysical data, so I’d like to produce a depth profile. The y-axis would be...
  • Doug: @Ashok First, please do not use variable names that are MATLAB commands (std and mean). Second, p(j) should be...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.