You are on page 1of 9

Temel MATLAB Komutlar

Getting Help help On-line help, display text at command line help, by itself, lists all help topics help topic provides help for the speci.ed topic help command provides help for the speci.ed command help help provides information on use of the help command helpwin On-line help, separate window for navigation. helpdesk Comprehensive hypertext documentation and troubleshooting demo Run demonstrations intro Interactive introduction to Matlab Special variables: ans: default variable name pi: ratio of circle circumference to its diameter, = 3.1415926... eps: smallest amount by which two numbers can di.er inf or Inf : in.nity, e.g. 1/0 nan or NaN : not-a-number, e.g. 0/0 date: current date in a character string format, such as 19-Mar-1998. flops: count of .oating-point operations. Commands involving variables: who: lists the names of de.ned variables whos: lists the names and sizes of de.ned variables clear: clears all variables, resets default values of special variables clear var: clears variable var clc: clears the command window, homes the cursor (moves the prompt to the top line), but does not a.ect variables. clf: clears the current .gure and thus clears the graph window. more on: enables paging of the output in the command window. more off: disables paging of the output in the command window. When more is enabled and output is being paged, advance to the next line of output by pressing Enter ; get the next page of output by pressing the spacebar. Press q to exit out of displaying the current item.

Punctuation and Comments Semicolon (;) at the end of a command suppresses the display of the result 23 Commas and semicolons can be used to place multiple commands on one line, with commas producing display of results, semicolons supressing Percent sign (%) begins a comment, with all text up to the next line ignored by Matlab Three periods (. . .) at the end of a command indicates that the command continues on the next line. A continuation cannot be given in the middle of a variable name.

Basic Mathematical Functions

abs(x) Absolute value |x| sign(x) Sign, returns -1 if x < 0, 0 if x = 0, 1 if x > 0 exp(x) Exponential ex log(x) Natural logarithm ln x log10(x) Common (base 10) logarithm log10 x sqrt(x) Square root .x rem(x,y) Remainder of x/y. For example, rem(100,21) is 16. Also called the modulus function.

format compact Displaying Values and Text There are three ways to display values and text in Matlab, to be described in this section: 1. By entering the variable name at the Matlab prompt, without a semicolon. 2. By use of the command disp. a. disp(variable): Displays value of variable without displaying the variable name. b. disp(string): Displays string by stripping o. the single quotes and echoing the characters between the quotes. >> temp=78; >> disp(temp); disp(degrees F) 78 degrees F

3. By use of the command fprintf.


fprintf(format string, list of variables) w.d%f Display as .xed point or decimal notation (defaults to short), with a width of w characters (including the decimal point and possible minus sign, with d decimal places. Spaces are .lled in from the left if necessary. Set d to 0 if you dont want any decimal places, for example %5.0f. Include leading

zeros if you want leading zeroes in the display, for example %06.0f. w.d%e Display using scienti.c notation (defaults to short e), with a width of w characters (including the decimal point, a possible minus sign, and .ve for the exponent), with d digits in the mantissa after the decimal point. The mantissa is always adjusted to be less than 1. w.d%g Display using the shorter of tt short or short e format, with width w and d decimal places. \n Newline (skip to beginning of next line)

DOSYA KOMUTLARI
Matlab File Management Matlab provides a group of commands to manage user .les that are similar to those of Unix. For more information, type help iofun. pwd: Print working directory displays the full path of the present working directory. cd path: Change to directory (folder) given by path, which can be either a relative or absolute path. dir or ls: Display the names of the directories (folders) and .les in the present working directory. what: Display the names of the M-.les and MAT-.les in the current directory. delete .le: Delete .le from current directory type .le: Display contents of .le (text .le only, such as an M-.le).

Diary Command
The diary commands allows you to record all of the input and displayed output from a Matlab interactive workspace session. The commands include: diary .le: Saves all text from the Matlab session, except for the prompts (>>), as text in .le, written to the present working directory. If .le is not speci.ed, the information is written to the .le named diary. diary off: Suspends diary operation. diary on: Turns diary operation back on. diary: Toggles diary state Storing and Loading Workspace Values save Stores workspace values (variable names, sizes, and values), in the binary .le matlab.mat in the present working directory save data Stores all workspace values in the .le data.mat save data_1 x y Stores only the variables x and y in the .le data_1.mat

load data_1 Loads the values of the workspace values previously stored in the .le data_1.mat Exporting and Importing Data save data1.dat -ascii A = csvread(file) Reads a comma separated value formatted .le file. The result is returned in A. The .le can only contain numeric values. csvwrite(file,A) Writes matrix A into file as comma separated values. A = wk1read(file) Reads all the data from a WK1 spreadsheet .le named file into matrix A. wk1write(file,A) Writes matrix A into a WK1 spreadsheet .le with the name file. .wk1 is appended to the .lename if no extension is given.

Script M-Files

Two-Dimensional Plotting
>> J= [1,2,3,4,5,6,7,8,9,10]; >> z=4-2*J; >> plot(z,'g.')

2D Plotting Commands

Customizing Plot Axes

Adding New Curves

Printing Figures and Saving Figure Files >> print % prints the current plot to the system printer

Arrays and Array Operations


Vector Creation by Explicit List

>> x=[0 .1*pi .2*pi .3*pi .4*pi .5*pi .6*pi .7*pi .8*pi .9*pi pi] Vector Addressing >> x(3) >> x(1:5) 1:5 means start with 1 and count up to 5. >> x(7:end) 7:end means start with 7 and count up to the end of the vector. >> x(3:-1:1) 3:-1:1 means start with 3 and count down to 1. >> x([8 2 9 1]) A vector can be used to access elements of an vector in a desired order. To access elements 8, 2, 9, and 1 of y in order: Vector Creation Alternatives Combining: A vector can also be de.ned using another vector that has already been de.ned. For example: >> B = [1.5, 3.1]; >> S = [3.0 B] S= 3.0000 1.5000 3.1000 Changing: Values can be changed by referencing a speci.c address. For example, >> S(2) = -1.0; >> S S= 3.0000 -1.0000 3.1000 changes the second value in the vector S from 1.5 to -1.0. Extending: Additional values can be added using a reference to a speci.c address. For example, the following command: >> S(4) = 5.5; >> S S= 3.0000 -1.0000 3.1000 5.5000 extends the length of vector S from 3 to 4. Applying the following command >> S(7) = 8.5; >> S S= 3.0000 -1.0000 3.1000 5.5000 0 0 8.5000 Vector Length >> x = [0 1 2 3 4 5] >> length(x) ans = 6

>> c = [1;2;3;4;5] c= 1 2 3 4 5

Matrix Arrays
>> f = [1 2 3; 4 5 6] f= 123 456

Element-by-Element Array-Array Mathematics

Array Plotting Capabilities

Plot Linestyles

You might also like