Loren on the Art of MATLAB

Archive for the ‘Best Practice’ Category


Loren Shure works on design of the MATLAB language at The MathWorks. She writes here about once a week on MATLAB programming and related topics.

  • Loren: Ben- The reference link in my post documents the behavior of sum([]) and prod([]) (although the prod part only...
  • Ben: Loren/Andrey, A further advantage of having sum([])==0 and prod([])==1 is that it’s consistent with array...
  • Loren: OysterEngineer- I will SO take you up on that offer. Can’t wait for a good reason to visit now....
  • OysterEngineer: You know, I really do farm oysters part time. Give me some advance notice next time you are in this...
  • Loren: Andrey- Thanks for your thoughts. One way to think about why empty shouldn’t error for sum is the...
  • Andrey: Hi Loren! IMHO, sum([]) and prod([]) should throw an error, as most of the times it shows that some kind of...
  • Loren: OysterEngineer (love the name, by the way!)- Initializing with an empty to start a concatenation process makes...
  • Loren: Wes- Implicitly there are trailing 1 dimensions for all arrays in MATLAB. But they do get dropped by ndims,...
  • Loren: Janti- Check out the function bsxfun. It will do exactly what you are hoping - not expanding vectors to arrays...
  • Wes: I generally find MATLAB’s handling of empties to be fairly consistent. It helps to think of an M-by-N...

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