Umal-qura university


Example: Entering a single variable



Yüklə 0,73 Mb.
səhifə4/30
tarix23.12.2023
ölçüsü0,73 Mb.
#156716
1   2   3   4   5   6   7   8   9   ...   30
Signal and Systems Manual - v2full

Example: Entering a single variable

>> x=input('Enter a variable: ')


Enter a variable: 4 x =


4


Example: Entering a vector

A vector is entered by specifying [] and elements are inserted inside these brackets, separated by space.


>> x=input('Enter a vector: ') Enter a vector: [3 4 1]


x =

3 4 1



Example: A \n entered after the string results in starting a new line.

>> x=input('Enter a value\n') Enter a value


5

x = 5





      1. DISP

DISP Display array.
DISP(X) displays the array, without printing the array name. In all other ways it's the same as leaving the semicolon off an expression except that empty arrays don't display.
DISP(‘string’) is another variation of the same function that is used to display a string on the command prompt.


Example:

>> disp('I am using MATLAB 7.0') I am using MATLAB 7.0




    1. M-Files

Typing errors are time‐consuming to fix if you are working in the command window because you need to retype all or part of the program. Even if you do not make any mistakes, all of your work may be lost if you inadvertently quit MATLAB. To preserve large sets of commands, you can store them in a special type of file called an M‐file. MATLAB supports two types of M‐files: script and function M‐files. To hold a large collection of commands, we use a script M‐file. The function M‐file is discussed in coming lab. The script file has a '.m' extension and is referred to as an M‐file (for example, myfile.m myfuncion.m, etc.). The commands in the script file can then be executed by typing the file name without its extension in the command window. Commands in a script utilize and modify the contents of the current workspace. It is possible to embed comments in a script file.


To make a script M‐file, you need to open a file using the built‐in MATLAB editor. There are two ways


to accomplish it:

  1. From file menu, click NEW

  2. Type edit on command line

A new window appears like one shown in the figure below.

When you are finished with typing in this new window, click File‐>Save to save this file. The extension


of this file be .m. In order to execute this program,



  1. Write the name of file on command window (excluding the .m) or

  2. Click Debug‐>Run


Yüklə 0,73 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9   ...   30




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə