Introducing MATLAB
Introducing MATLAB
INTRODUCING
MATLAB
Introduction to MATLAB
2
Help lists related functions at the bottom and links to the doc
Matrices are the fundamental object of MATLAB and it can be created in MATLAB in
many ways, the simplest one obtained by the commands
The matrices can be multiplied, for example E = A∗D, as shown in the following
example
String
Note: Strings
Prepared are Mechanical
by AAiT, written inEngineering
single quote and disp
Department is used to display string
2012
LOOPS: for and while
11
Some MATLAB functions are applied to scalars only,such as those listed below
Table 1.4. Scalar functions
Note that such functions can be applied to all elements of a vector or matrix,
as in
And, some MATLAB functions operate on vectors only, such as those illustrated in
Table 1.5. Vector functions
Consider for example vector X=1:10. The sum, mean and maximum values are
evaluated as
Some important matrix functions are listed in Table 1.6. Matrix functions
In some cases such functions may use more than one output argument, as in
or using increments
Logical indexing arise from logical relations, resulting in a logical array, with
elements 0 or 1.
Then we can use such array as a mask to modify the original matrix, as shown
next.
A M-file is a plain text file with MATLAB commands, saved with extension .m.
The M-files can be scripts of functions.
By using the editor of MATLAB we can insert comments or statements and then
save or compile the m-file.
Note that the percent sign % represents a comment.
No statement after this sign will be executed. Comments are quite useful for
documenting the file.
M-files are useful when the number of statements is large, or when you want
to execute it at a later stage, or frequently, or even to run it in background.
producing
Using the command plot, we can produce simple 2D plots in a figure, using two vectors
with x and y coordinates. A simple example
As for 2D plots, we can produce 3D plots with plot3 using x, y, and z vectors. For
example
The End!
Prepared by AAiT, Mechanical Engineering Department 2012