Creative Commons License Copyright © Michael Richmond. This work is licensed under a Creative Commons License.

Project 0: Learning a little Matlab

Due at the end of the first class meeting

On your first day, you should learn enough to get started:


The "Hello, world" program in MATLAB

Run MATLAB, and use the editor to create a source code file which looks exactly like this:

function hello
%
%  Print a message and quit.
%

  fprintf(1, 'Hello, world \n');

Save this file as hello.m, and then, in the MATLAB command interpreter, type hello to execute the program. Does it work?

Now, edit your program so that it is a bit more complex:

function hello
%
%  Print a message repeatedly.
%

  for (iter = 1 : 10)
    fprintf(1, 'Hello, world 0 \n', iter);
  end

Again, save this as hello.m and then execute it. What happens this time?


The mini-challenge

While you are here today in class, try to modify your program so that it counts to 10, but prints out a series of messages like this:

        Hello, world   1  is odd 
        Hello, world   2  is even 
        Hello, world   3  is odd 
        Hello, world   4  is even 

and so forth up to 10. Can you figure out how to do it? You might look at the Introduction to MATLAB page for some hints on the syntax of if-then . There are several ways to determine if an integer is even or odd; you might use the help facility in MATLAB to examine its builtin functions,

When you are done, submit your MATLAB source code to me using the Post File command on the myCourses WWW page.


This page maintained by Michael Richmond. Last modified Mar 9, 2003.

Creative Commons License Copyright © Michael Richmond. This work is licensed under a Creative Commons License.