Matlab

Páginas: 22 (5481 palabras) Publicado: 6 de enero de 2011
Matlab Tutorial

A Jump Start into Matlab
by

Klaus Moeltner
Department of Resource Economics
University of Nevada, Reno (UNR)
Mail Stop 204 / Reno, NV 89557-0105
phone: (775) 784-4803
email: moeltner@cabnr.unr.edu
web: http://www.ag.unr.edu/moeltner

August 21, 2008

Specifically designed as a 1/2 day "bare-bones" introduction to Matlab for
beginning Graduate Econometricsstudents

Comments & suggestions are always welcome!

Tutorial web site:
http://www.ag.unr.edu/moeltner/matlab_stuff.htm
I. Work Environment
Folder Structure
Create the following folder environment on your c:\ drive or any other path destination.

[pic]
For example, for this tutorial, you could first create a folder c:\mlab_tut\. Then, within this folder, create the folder structure shownabove.

Your main command scripts go into "scripts". Your sub-routines go into "functions". "Worksp" (short for "workspace") contains your data and other saved elements. Output goes into "logs".

Matlab Windows and Matlab Path
When you open Matlab you will first see the command window. This is where you can enter interactive commands.

File/new/m-file will open an editor window. This iswhere you write your programs (scripts and functions). We'll come back to this in a moment. To close the editor window click on the red "x" in the upper right hand corner. If you have multiple editor files open, close them individually by clicking on the specific "x" in the bottom bar of the editor window. By the way, scripts and functions are called "m-files" in Matlab jargon.Desktop/workspace will open the workspace window, which shows you all elements currently in your workspace. For matrix elements, you can double-click on them & Matlab will open a separate spreadsheet showing the detailed contents of the matrix. To close the workspace window, simply click on the little "x" in the upper right hand corner.

File/set path will allow you to "set the path", i.e. to tell Matlabwhich folders to visit when looking for files. To add the entire folder environment created above to the path, simply click on "add with subfolders", then find your "mlab" folder created above in the browser window, click "OK" and "save".
Your folder cluster will now be "on the path", at the very top.

Note: If you access Matlab via the UNR library server you will not be allowed to save the path.Just add your files to the path as described above, then click “Close”, and “No” to the question “Do you want to save your path?”. Your files will be on the path for the current session. You will have to repeat these steps every time you log on to the server and use Matlab.

II. A Basic Script with Programming Essentials and Random Data Generation

Open a new editor. Save the file asc:\mlab_tut\mlab\scripts\script1. A basic script will have the following structure:

• A comment (note) to yourself about the script
• set seeds for random draws (that way you will always be able to replicate your work precisely)
• set timer (that way you'll always know how long your program takes to run)
• open log file (tell Matlab where to send your output)
• Main script. Will likelycontain elements such as:
o load or generate data
o call sub-routines (functions)
o format output for your log file
o save output elements to your workspace
• stop timer & capture run time for your log file
• close log file

Comments
Any line or cluster of elements in your editor starting with "%" will be interpreted as a comment and NOT executed as a command. Lets' startwith the following comment:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is practice script 1 for the Matlab tutorial%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Set Random Number Seeds
You need to set seeds for the uniform and normal distribution. All other random numbers will be based on those. Example: Choose seed state "37" (any other number will do as...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • matlab
  • Matlab
  • Matlab
  • matlab
  • MATLAB
  • MATLAB
  • Matlab
  • Matlab

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS