Ex4 : Introduction to Matlab Programming

This exercise will help us start working with matlab. By this exercise you will teach yourselves the basics of Matlab.
In class we will continue to learn together more advanced commands and applications.
You should do this exercise on your own. Deadline : Wednesday - May 26 (Until our class, at 11:00)

How to start ?

Use one of the many excellent tutorials that are on the web. This tutorial is recommended.
There is also a Matlab guide in Hebrew here.
Each command in Matlab has clear documentation, you can see it by typing "help" or "doc" with the name of the command after it.

The purpose of the following question is to make sure you are familiar with the basic concepts and functions in Matlab.
Your code should be simple and efficient. In general, when working in Matlab always prefer matrix operations (multiplications and such) over loops.
You can open Matlab from your shell by simply writing matlab.
Write a short Matlab function named ex4 which does the following:
  1. Create a vector of ones, of size 10, and print it to the screen (note if you omit the ";" at the end of a command, the result will be printed to the screen)
  2. Creates a ROW vector of size 100 with all even numbers from 2 to 200
  3. Print to the screen the numbers at index 15-20 in this vector
  4. Creates a COLUMN vector of size 100 with all odd numbers from 1 to 199. Save both vectors to a matlab file named dat.mat (use the command save)
  5. Receive the name of a matlab file as a parameter to this function (file ending with .mat), you can assume this file contains a single matrix variable named M. upload the matrix from the file (check out the command load)
  6. Check if the matrix is square (.. the size of the matrix), if not print the error message "Mat not square!" and exit
  7. Check if the matrix is the identity matrix, if so print the message "Identity!", and create a square random matrix the size of the input matrix, with values between 0-100, and continue working with it (the command rand can help you here)
  8. Create a plot containing two subplots, side by side as following: (check the commands plot, subplot,xlabel, ylabel, title,hist,sum)
  9. And now let's do some math :

  10. What to submit ?

    Submit your code in a file named ex4.m (same as the name of your function)

    Good Luck!