Professional Documents
Culture Documents
MATLAB Basics: - MATLAB Desktop - Command Window - Scripts - Practice
MATLAB Basics: - MATLAB Desktop - Command Window - Scripts - Practice
MATLAB Basics
Overview
MATLAB Desktop Command Window Scripts Practice
01-Oct-11
MATLAB Desktop
Help Browser Current Folder The prompt Function Browser
Workspace Browser
What are the usages of these items? Try it and take notes
01-Oct-11
MATLAB Desktop
Write and calculate simple and complex equations in the command window Observe the workspace browser and the command history. How their contents are affected? Use the help browser then the function browser to learn and to get the square root of a number x.
Command Window
User Input (What you typed) Calculation Results (What MATLAB computed from your statement)
01-Oct-11
Command Window
Use the Up and Down keys while in the command window Double click any line in the command history Add semi-colon at the end of your statement in the command window. Type whos in the command window. What do you get? Type clc in the command window. What happened?
Creating Scripts
Change the current folder to C:\ and observe the Path Browser contents Change the current folder to your FirstLastName folder From MATLAB desktop menu select File New Script Type the following commands in the opened editor Save this file as firstProgram Click the Green Arrow to run these commands Check the output in the command window What is the purpose of this script?
01-Oct-11
Script Contents
a = 1; b = 5; c = 6; d = sqrt(b^2 - 4*a*c); r1 = (-b - d)/(2*a) r2 = (-b + d)/(2*a) Why to use script?
01-Oct-11
Editing Scripts
Go to your FirstLastName folder on Windows desktop Double click to open your firstProgram file Edit this script by adding your name at the beginning of the script. Use % before your name. Why? Re-run the script and see the output at the command window.
Practice
1. Write and execute a script to calculate the area of a rectangle
area=length x width;
2. Write and execute a script to calculate the distance between two points (x1,y1) and (x2,y2)
dist=sqrt((x2-x1)^2+(y2-y1)^2);
3. Write and execute a script to calculate your own equation. (Bonus will be given to good ideas) All scripts should be stored in your FirstLastName folder and have clear names.