• Sonuç bulunamadı

MATLAB Tutorial - Introduction ES 111 1/4

N/A
N/A
Protected

Academic year: 2021

Share "MATLAB Tutorial - Introduction ES 111 1/4"

Copied!
4
0
0

Yükleniyor.... (view fulltext now)

Tam metin

(1)

MATLAB Tutorial - Introduction

ES 111 1/4

INTRODUCTION

This tutorial is intended to acquaint you with MATLAB, which is used in many of the courses you will take at New Mexico Tech. The shaded boxes indicate what you should see in the MATLAB command window as you progress through the tutorial. The directions are there to guide you through it. As you perform the tutorial, think about what you are doing and why you get the results that you get. You are encouraged to try other things that you do not see in the tutorial for better understanding and more familiarity with the program.

GETTING STARTED

Double click on the MATLAB icon or open it from the start menu. Depending on the platform one or more windows may open up. For this tutorial, you will only be using the Command Window which looks like (depending on the version of MATLAB):

To get started, select "MATLAB Help" from the Help menu.

>>

A cursor appears at the command prompt (>>). All variable definitions, calculations, and plotting should be performed at the command prompt.

VARIABLES AND OPERATIONS

Values can be assigned to variables with names. If a name is not given to a value, the default name is ‘ans’. The variable names are case sensitive and must start with a letter.

>> a=3 a = 3

>> 8+9 ans = 17

>> oranges=8 oranges =

(2)

MATLAB Tutorial - Introduction

ES 111 2/4

8

>> Oranges=3 Oranges = 3

When doing a long set of calculations, it is often better not to print out the result of each step. You can avoid this by adding a semicolon (;) at the end of a line. Remember the semicolon is your friend.

>> b=6;

>>

Notice how nothing printed out from the declaration for ‘b’.

If you have assigned many variables, there are two helpful commands to find out which variables have been assigned, who and whos. ‘whos’ gives more information than ‘who’.

>> who

Your variables are:

Oranges a ans b oranges

>> whos

Name Size Bytes Class

Oranges 1x1 8 double array a 1x1 8 double array ans 1x1 8 double array b 1x1 8 double array oranges 1x1 8 double array Grand total is 5 elements using 40 bytes

The variables can be added, subtracted, multiplied, etc.

>> c=a+b c = 9

(3)

MATLAB Tutorial - Introduction

ES 111 3/4

>> d=a-b d = -3

>> e=c*d e = -27

>> f=c/d f = -3

If you would like to reset the value of the variables you can use the ‘clear’ command.

Notice how after using ‘clear’ the ‘whos’ command has no output.

>> clear

>> whos

>>

MATLAB has some built in variables. Pi is the best example. Be careful, pi can be redefined to be a different value. This can be fixed by using the ‘clear’ command.

>> pi ans = 3.1416

>> pi=100;

>> pi pi = 100

>> clear

>> pi ans = 3.1416

(4)

MATLAB Tutorial - Introduction

ES 111 4/4

FUNCTIONS

There are several pre-defined functions in MATLAB.

For the log function, ‘log10( )’ gives the base 10 log value of the input and ‘log( )’ gives the natural log value of the input. Make sure to put the input in the parentheses or the function will not work.

>> log10(100) ans =

2

>> log(10) ans = 2.3026

>> log10

??? Error using ==> log10 Not enough input arguments.

Other functions include trigonometric functions such as sine, cosine, etc., but make sure the argument is in radians and not degrees.

>> sin(90) ans = 0.8940

>> sin(pi/2) ans = 1

FINAL NOTE

Once you have finished, it would be a good idea to “play” around with the material covered in this tutorial and other tutorials you will be given. Try doing things incorrectly to see what happens in order to better understand why things work the way they do.

This tutorial is intended to give you the very basics of MATLAB useful for this class. If you would like to look at more advanced tutorials go to the MATLAB website.

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.html

Referanslar

Benzer Belgeler

FESHANE ÖNERİLERİVasıf Kortun, Sergilediği eselerden dolayı çağdaş, sürekli, sabit koleksiyon sergilerine dayanmadığı için geçici olacaktır.. FESHANE

The developed system is Graphical User Interface ( MENU type), where a user can load new speech signals to the database, select and play a speech signal, display

Identify the new largest element in the original vector Make that value the 2 nd element in the sorted array Cross out the element in the original array.. **Repeat so that

 Reduce the number of blocks display on the main window (i.e. simplify the model).  Group related blocks together (i.e. More

Matlab ile hazır olarak kullanılan conv,conv2,convn hazır fonksiyonları bulunmakla birlikte konvolüsyon sonucunun ‘0’ sıfır indisli değerinin de bulunması için

Şekil 7’deki peş peşe bağlı revize edilmiş akson model bloğu göz önüne alınarak, sistemin Simulink modeli Şekil 12’de görüldüğü gibi oluşturulmuştur..

Workspace penceresinde hafızadaki değişkenler hakkında bilgi edinme ve işlem yapmaya ek olarak yeni değişkenler oluşturmak veya hafızadaki değişkenleri de

Nokta işareti aynı zamanda eleman elemana çarpma ve bölme işleminde de kullanılır.. Bir tek satıra sığmayan ifadelerin bir alttaki satırda devam