5.1 Assignment

Assignment is the method of giving a value to a varaiable. You have already seen this in the interactive mode. We write x=a to give the value of a to x. Here is a short program illustrating the use of assignment.

function r=mod(a,d)

% r=mod(a,d). If a and d are integers, then r is the integer
% remainder of a after division by d. If a and d are integer
% matrices, then r is the matrix of remainders after division
% by corresponding entries. Compare with MATLAB's rem.

r=a-d.*floor(a./d)



You should make a file named mod.m and enter this program exactly as it is written. Or you can download it.

If you are using MATLAB on a PC you will need to set path so that MATLAB can find you program. To do this click on File in the menu bar and then click on set path. Next select the folder the contains your m-file and click save. Now you can call the function from within MATLAB.

Now assign some integer values for a and d. Run

mod(a,d)

This should run like any builtin MATLAB function. Type

help mod

This should produce the comments that follow the % signs. Now type

type mod

This will give a listing of the file.


Next Section: 5.2 Branching


Created by F.G. Garvan (fgarvan@ufl.edu) on Wed, Oct 01, 97
Last update made Thu May 27 15:38:47 EDT 2004.
Back to 5. Programming in Matlab
Back to Table of Contents
EMAIL: fgarvan@ufl.edu fgarvan@ufl.edu