Information Technology Services Centre
The Chinese University of Hong Kong
WKS404 MATLAB for UNIX QUICK START GUIDE
Version 1.3 November 2007

1. Introduction

MATLAB is a technical computing environment for high-performance numeric computation and visualization. MATLA integrates numerical analysis, matrix, computation, signal processing, and graphics in an easy-to-useenvironment where problems and solutions are expressed just as they are written mathematically - without traditional programming.

The only data type in MATLAB is the matrix, a rectangular array of possibly complex floating-point values, which need not be dimensioned, and whose size and shape can vary dynamically.

MATLAB for UNIX, Version 7.1, available on the General-purpose UNIX Server (Logic).

2. Access to Matlab on 'Logic'

'Logic' is accessible via ssh at logic.itsc.cuhk.edu.hk. Refer to ITSC Quick Start Guide WKS003 Use of General-purpose UNIX Server (Logic) for the access details. After successful connection,

3. Running Matlab

5. Handling With Data File

MATLAB uses and creates several types of files

  • M-file (with extension .m, e.g. prg_main.m)
    A collection of MATLAB statements and variables.
    There are 2 types of M-files: Script and Function.
Script 
Function 
Definition:  A collection of MATLAB commands  User-defined function to solve user-specific problem. 
Characteristics:  Null  The word 'function' at the beginning of the first line. 
Variables:  Global.  Local (variables are passed into the function as local variables). 
Usage:  Type the script filename and press ? .  Used as function call; e.g. mean is a function, call it as mean (1,2,3). 
  • MAT-file (with extension .mat, e.g. prg_data.mat)
    Binary file stores matrices/variables with data.
     
  • ASCIIfile (with or without extension, e.g. prg_data, or pro_data.dat)
    Contains a rectangular array of numeric data, arranged in m lines with n values in each line, each is separated with spaces.
     
  • Other advanced data files (refer to MATLAB manuals)
6. Disk File Operation
  • Load statements from M-file
    >> M-file
     
  • Load variables from MAT-file
    >> load MAT-filename
     
  • Load data from ASCII file
    >> load ASCII-filename
    (The result is a m-by-n matrix with the same name as the file with the extension stripped)
     
  • Save variables to MAT-file
    >> save MAT-filename
    (.mat will be appended at the end of the filename)
     
  • Save data to ASCII file
    >> save ASCII-filename -ascii
Other useful commands:
 
Command 
Purpose 
diaryfilename save session in a disk file, but no graphics, useful for inclusion into documents and reports 
dir  show current directory 
typefilename show file content 
delete  delete file 
cd  change directory 
reset of the input line is issued as a command to the UNIX system 

7. Handling With Graphics/Printing

In order to display graphics in MATLAB, please access from X-terminal, PC-XView, X-window or Macintosh.

  • Basic graphical function:
    plot, bar, hist, compass, polar, staris, fill, contour, mesh, image...
    All are in the format of
    function(variable) or
    function(variable, variable, variable..)
     
  • Print the M-file, ASCII file, diary to the system LINE printer:
    >> !lp filename
    or go back to UNIX system prompt and then type lp file
     
  • Set hardcopy paper orientation for printing figure:
    >> orient landscape or
    >> orient portrait or
    >> orient map
    (map maps to the whole page in portrait orientation)
     
  • Print the figure to a file in PostScript format:
    >>print filename
     
  • Print the figure to a file in specific format:
    >>print -d device filename 
     
  • At ITSC, or print the figure, you have to print to a file and transfer it to PC/Mac. Then print it with any popular PC/Mac software.
8. Getting More Information

MATLAB demonstration:

>> demo

Online documents:

>> help topic
Introduction to MATLAB:
>> intro
Keyword search through all help entries:
>> lookfor topic
Display listing of M-files, MAT-files:
>> what
New features in version 4.2a
>> whatsnew
Locate functions and files:
>> which function_name
List directory of variables in memory:
>> who
9. References

9.1 Manuals

  1. MATLAB user"s Guide
  2. MATLAB Reference Guide

9.2 Others

10. Enquiries

For any enquiries, please contact us by:

Website: http://www.cuhk.edu.hk/itsc
Electronic HelpDesk: https://helpdesk.itsc.cuhk.edu.hk/group/matlab-help

Fax:    2603-6946
Phone: 2609-8845 (Hotline Services)

Monday - Thursday 08:45-13:00 14:00-17:30
Friday 08:45-13:00 14:00-17:45
Saturday, Sunday & Public Holiday close