Loren on the Art of MATLAB

Results for: Readability

Find Largest Positive Value Next to Zero 19

Posted by Loren Shure,

Find Largest Positive Value Next to Zero  Recently, Steve wrote a blog discussing code clarity/obscurity in the context of one-line code solutions. Simply stated, the problem he solved is this. Find the largest value in an array adjacent to a zero value. ... read more >>

Switching Things Up 22

Posted by Loren Shure,

Switching Things Up  If you have ever used a switch statement in MATLAB and also used it in C, you might have noticed that the two constructs have different semantics. Contents ... read more >>

Vectorizing the Notion of Colon (:) 14

Posted by Loren Shure,

Vectorizing the Notion of Colon (:)  The other day, one of my MathWorks buddies, Peter, asked me if I knew any tricks for vectorizing the notion of the colon (:) operator. For me, this sort of inquiry sometimes has an effect similar to waving a flag in... read more >>

A Way to Automate “Regular” Renaming 17

Posted by Loren Shure,

A Way to Automate “Regular” Renaming  Recently someone at MathWorks asked me how he could automate the renaming of a bunch of M-files containing underscores ('_') in the names with derived names that removed the underscores and used camelCasing instead. You may have similar name manipulation operations... read more >>

Deal or No Deal 21

Posted by Loren Shure,

Deal or No Deal  This post continues in the theme from my last post, where people routinely come to me on a topic. Today I want to distinguish between indexed assignment, where you can take advantage... read more >>

Nested Functions and Variable Scope 35

Posted by Loren Shure,

Nested Functions and Variable Scope  I get a parade of questions about which variables are available to nested functions and which variables, used in nested functions, are part of the nesting function workspace. So today I thought... read more >>

for Versus while 33

Posted by Loren Shure,

for Versus while  A reader suggested I discuss the difference in use of MATLAB's for and while constructs. Contents ... read more >>

Brief History of Nonnegative Least Squares in MATLAB 12

Posted by Loren Shure,

Brief History of Nonnegative Least Squares in MATLAB  In my first year at MathWorks (1987!), a professor I know got in touch with me. He was trying to solve a least squares problem with nonnegativity constraints. Having been raised... read more >>

Mental Model for feval 11

Posted by Loren Shure,

Mental Model for feval What's your mental model for when to use the MATLAB function feval? Until Release 14 (MATLAB 7), feval was the way to evaluate a function handle. By that I mean you might write code something like this: function y = halfcircle(fun,n) if nargin < 2 n = 20; end y... read more >>

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