Programming Fundamentals Using MATLAB, 2020, Book errata


The chapter on sound shows an example with "case 'b'" followed by "case 'B'". While this code works in that it does not generate an error, it does not work as intended. MATLAB does not have fall-through case statements like other programming languages. This means that nothing will be done when the first "case" matches.

code from "note_play2.m":
      case 'A'
        n = 2;
      case 'b'
      case 'B'
        n = 3;
      % ...
      case 'e'
      case 'E'
        n = 8;
This should be either:
      case 'A'
        n = 2;
      case 'b'
        n = 3;
      case 'B'
        n = 3;
      % ...
      case 'e'
        n = 8;
      case 'E'
        n = 8;
or perhaps:
      case 'A'
        n = 2;
      case {'b', 'B'}
        n = 3;
      % ...
      case {'e', 'E'}
        n = 8;


A couple instances of the imwrite command show commas around some arguments, when they should be single quotes. That is, on pages 268 and 270, the following line appears.
      imwrite(z, ‚bee.png‚, ‚PNG‚, ‚Alpha‚, alpha);
It should instead be:
      imwrite(z, 'bee.png', 'PNG', 'Alpha', alpha);

-Michael Weeks