matlab-novice-inflammation icon indicating copy to clipboard operation
matlab-novice-inflammation copied to clipboard

Include vectorization

Open shwina opened this issue 10 years ago • 7 comments

In a discussion with Ken Deeley and Jos Martin from Mathworks, and @gvwilson, the following improvements to the SWC MATLAB material have been suggested:

  1. MATLAB environment - the lessons don't have, for instance, screenshots of the MATLAB environment. While this reduces maintenance costs, it might also make learning more difficult for beginners. Greg's suggestion: short GIFs/videos of the MATLAB environment
  2. Vectorization - effective use of MATLAB entails familiarity with the idea of vectorization. We should introduce this in some depth in our lesson.

shwina avatar Feb 19 '15 19:02 shwina

Where do you thing vectorization should go? Before or after loops? Are we including logical indexing? I'm hoping this is not too confusing since we're already teaching loops.

IsaKiko avatar Feb 20 '15 03:02 IsaKiko

The MATLAB folks think vectorization should come first, and loops later

  • this is part of why we start with whole-array operations, then show loops over all input files (because that doesn't vectorize).

gvwilson avatar Feb 20 '15 12:02 gvwilson

I think it's worth having learners use both approaches to accomplish the same task, have them understand why vectorization is generally a better idea, and also when it becomes necessary to use a for loop. The challenge will be making sure all of this doesn't stick out awkwardly in the lessons :)

shwina avatar Feb 20 '15 17:02 shwina

We now have a screenshot of MATLAB, and a gif of debugging. I'll have a think about how to cover vectorisation

gcapes avatar Jun 21 '21 13:06 gcapes

Some thoughts: The arrays episode (2) is quite short, so could probably accommodate some examples of whole-array operations, assignment to a slice, and logical indexing which is important in vectorization.

In ep5 (loops) some of the examples would be much better achieved using whole-array operations e.g. printing each letter in a word, summing all the elements of an array etc. So while they're poorly-motivated examples of loops, they are easy to follow examples, and give a natural motivation for vectorization. We could show how some of these examples could be achieved using vectorization, and come up with an example which doesn't vectorize before looping over files (which also doesn't vectorize).

gcapes avatar Jun 21 '21 14:06 gcapes

I'm interested in having a crack at adding some vectorization material to the lessons as I think it's an important part of using MATLAB.

@gcapes - these are great suggestions. I think it's sensible to introduce vectorization in the arrays lesson, but although the lesson is short the array indexing material is conceptually dense. I'll add some material and we can see how it looks.

cjfullerton avatar Nov 18 '22 10:11 cjfullerton

Would be good to see your ideas. Perhaps it might be useful to refer back to mean i.e. an inbuilt vectorised function which is previously used in the lesson

gcapes avatar Nov 18 '22 10:11 gcapes