Matlab

Mary PW Chin 钱碧慧博士
PhD (Wales), MSc (Surrey)
E-mail:

Matlab #1

Getting started

Matlab #2

Dice

Matlab #3

Circles

Matlab #4

Histograms

Matlab #1

Preliminaries
  1. You have 3 choices of running the programs presented on this site:
    • Matlab on your computer or network. Matlab license has to be paid for. Many institutions have Matlab licenses for staff and students.
    • Octave on your computer or network. In case you do not have access to any Matlab license, you may use Octave. Octave is free to download and install. It runs on Windows, Mac and Linux. Most Matlab and Octave programs can be used interchangeably. Programs given here have been tested on both Matlab and Octave.
    • Octave on PythonAnywhere. This option is highly recommended if you are starting fresh without pre-installed Matlab or Octave. You won't need to install anything anywhere, just follow the slides step by step.
  2. Flexi-programmers at Penang Science Cluster should keep a green exercise book recording all solved exercises. We'd like to be as green as possible — save your answers as files in a designated directory/folder for easy retrieval anytime in the future. For exercises you find difficult to put in soft copy e.g. flowchart drawing, you may draw by hand and retain the hard copy for easy retrieval in the future.
  3. Slides here are continuously being revised and updated. If you have been here before, your browser might have some old files cached. To ensure that you see the latest version, please follow the instructions here: ☞ how to clear browser cache.

Synopsis
  1. the 'fprintf' function;
  2. variables;
  3. arithmetic operators;
  4. running Matlab interactively vs running from saved .m files;
  5. auto-completion (TAB key) and command history (UP and DOWN arrow keys);
  6. for-end loops:
  7. sequence of numbers;
  8. commenting;
  9. the 'help' function.
Exercise
  1. Refer to the program on slide #33. What happens if we make five changes
    • the 'n' on line #16 to 'a';
    • the 'n' on line #22 to 'b';
    • the 'n' on line #28 to 'c';
    • the 'n' on line #34 to 'd';
    • the 'n' on line #40 to 'e',
    and then run? What changes on other lines do we need in order to make the program work?
  2. Write a program that prints the following with as few fprintf() functions as you can:
                 .oooooooooooooooooo.
                 .oooooooooooooooooo.
                 .oooooooooooooooooo.
                 .oooooooooooooooooo.
                 .oooooooooooooooooo.
                 .oooooooooooooooooo.
                 .oooooooooooooooooo.
                 .oooooooooooooooooo.
              
  3. Write a program that prints the following with as few fprintf() functions as you can:
                 .o.o.o.o.o.o.o.o.o.o
                 .o.o.o.o.o.o.o.o.o.o
                 .o.o.o.o.o.o.o.o.o.o
                 .o.o.o.o.o.o.o.o.o.o
                 .o.o.o.o.o.o.o.o.o.o
                 .o.o.o.o.o.o.o.o.o.o
                 .o.o.o.o.o.o.o.o.o.o
                 .o.o.o.o.o.o.o.o.o.o
              
  4. Write a program that prints the following with as few fprintf() functions as you can:
                 .ox.ox.ox.ox.ox.ox.ox
                 .ox.ox.ox.ox.ox.ox.ox
                 .ox.ox.ox.ox.ox.ox.ox
                 .ox.ox.ox.ox.ox.ox.ox
                 .ox.ox.ox.ox.ox.ox.ox
                 .ox.ox.ox.ox.ox.ox.ox
                 .ox.ox.ox.ox.ox.ox.ox
                 .ox.ox.ox.ox.ox.ox.ox
              
  5. Write a program that prints the following with as few fprintf() functions as you can:
                 .ooxxx.ooxxx.ooxxx
                 .ooxxx.ooxxx.ooxxx
                 .ooxxx.ooxxx.ooxxx
                 .ooxxx.ooxxx.ooxxx
                 .ooxxx.ooxxx.ooxxx
                 .ooxxx.ooxxx.ooxxx
                 .ooxxx.ooxxx.ooxxx
                 .ooxxx.ooxxx.ooxxx
              
  6. Write a program that prints the following with as few fprintf() functions as you can:
              *...*****.......*********
              *********.......*****...*
              *...*****.......*********
              *********.......*****...*
              *...*****.......*********
              *********.......*****...*
              *...*****.......*********
              *********.......*****...*
              *...*****.......*********
              *********.......*****...*
              


Matlab programming

Matlab #1

Getting started

Matlab #2

Dice

Matlab #3

Circles

Matlab #4

Histograms