Loren on the Art of MATLAB

Results for: Common Errors

Coding Best Practices – A Good Read 7

Posted by Loren Shure,

Coding Best Practices – A Good Read Coding Best Practices - A Good ReadI have written blogs before on coding best practices in MATLAB and they have always generated a lot of great feedback. I recently came across a language-neutral list of best practices for scientific computing, written by Greg Wilson of Software Carpentry.If you don't... read more >>

Understanding Array Preallocation 6

Posted by Loren Shure,

Today I would like to introduce guest blogger Jeremy Greenwald who works in the Development group here at MathWorks. Jeremy works on the Code Analyzer and will be discussing when preallocating MATLAB arrays is useful and when it should be avoided.... read more >>

What’s “if” “all” about? 12

Posted by Loren Shure,

I recently posted about a GOTCHA with the expression a < x < b in MATLAB and Matt's comments made me look to see if I had ever devoted a post to the behavior of all (or its companion any). So today I will explain how all works and why you need to take care when you use arrays for testing conditions in if and while statements. This is especially true if you do not use them with functions such as any or all since they can reduce expressions to scalar true and false values.... read more >>

Why is Answer to 3 < A < 7 Unexpected? 9

Posted by Loren Shure,

Why is Answer to 3 < A < 7 Unexpected?  There have been countless (not really!) times on the MATLAB newsgroup where a question of the sort written in the title has been asked (and answered). Let's go through the code to understand ... read more >>

Another Possible Surprise – Ignored NaN Values 9

Posted by Loren Shure,

Another Possible Surprise – Ignored NaN Values  Ever have some data that might have some NaN values? And you start doing computations with these data, expecting |NaN|s to propagate... Only to find later, that the |NaN|s only went... read more >>

Wash, Rinse, Repeat; Break, Return, Continue 4

Posted by Loren Shure,

Wash, Rinse, Repeat; Break, Return, Continue  So much of the work we do in development at MathWorks is iterative. Over the years, we've come to use the phrase "wash, rinse, repeat" to indicate this. It's true for... read more >>

size Does Matter Sometimes 18

Posted by Loren Shure,

size Does Matter Sometimes  Recently at work I was on an email thread where people were discussing the function size and how to use it reliably in the context of arrays that might be two dimensional but could have higher dimensions as well. ... read more >>

Scalar Roulette 4

Posted by Loren Shure,

Scalar Roulette  A while ago, Steve posted an article entitled Functional Design Clunkers on his blog. Well, I have a confession to make too. Have you ever been bitten by the ambiguity in the contour function? ... read more >>

Doug’s “Top 10 MATLAB code practices that make me cry” 5

Posted by Loren Shure,

Doug’s “Top 10 MATLAB code practices that make me cry”  Doug's "Top 10 MATLAB code practices that make me cry" This week, Doug's blog focuses on what he considers to be some poor programming practices he's seen in MATLAB code. I agree with much of his list, including, despite the... read more >>

A Case for Divergence between MATLAB and C 14

Posted by Loren Shure,

A Case for Divergence between MATLAB and C  There are some functions in MATLAB that we designed to be similar to their counterparts in other languages. There are also some functions that we deliberately designed differently. A case in... read more >>

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