MATLAB TUTORIAL - PART I

MATLAB is a powerful language for technical computing.

MATLAB means MATrix LABoratory, since the basic element in MATLAB is a matrix.

It is a very helpful mathematical tool used in all engineering computations, modelling and simulation, data analysis and processing, visualization and graphics, as well as algorithm development.

As you may know, MATLAB is huge so it is impossible to cover all MATLAB at once. So we will focus here on the foundations of MATLAB, and once understood, any topic will be easily understood. And of course, the HELP menu is a very rich source of information in case we are stuck.

In this part of the tutorial, we will describe the different windows in MATLAB, while concentrating on the Command Window. We will also deal with arithmetic operations with scalars. Of course, we will define the scalar variable first and then introduce the elementary math functions that can be applied on scalars.

The default view of MATLAB consists of 3 main windows which are :

  1. Command window
  2. Current directory window
  3. Command history window

And there is the start button in the lower left corner of the screen which is used to access MATLAB tools and features.

The purposes of the windows in addition to the 3 windows mentioned above are listed below:

  • Command window: main window, enters variables, runs programs
  • Figure window: contains output from graphic commands
  • Editor window: creates and debugs script and function files
  • Help window: provides help information
  • Launch pad window: provides access to tools, demos and documentations
  • Command history window: logs commands entered in the command window
  • Workspace Window: provides information about the variables that are used
  • Current directory window: shows the files in the current directory

Below are few notes for working in the command window:

  • To type a command, the cursor should be placed next to the command prompt >>
  • At the end of a command press the ENTER key to execute
  • Several command can be typed on the same line separated by a comma
  • It is not possible to go back to a previously executed line or command to make corrections and execute again except by pressing the ARROW UP key in order to recall the previously executed command.
  • If the command is too long, you can write (…) at the end of the line and continue on the next line. You can continue up to 4096 characters.

When executing the command, the output is directly displayed. But you can suppress the output if you end the line or command with a semicolon.

Also, the is the percent symbol % which is very used in MATLAB to declare that the line is a comment, and this will lead to not executing the line. In the command window, it is useless to use comments, but these are extensively used in scipts and programs.

Moreover, the clc command clears the command window ( not the variables stored).

Below are the Arithmetic operation used in MATLAB:

  1. Addition           +  like 6+10
  2. Subtraction       -  like 6-10
  3. Multiplication   *  like 6*10
  4. Right division   /  like 6/10
  5. Left division     \  like 6\10 = 10/6
  6. Exponentiation ^ like 6^10=60466176

Of course, calculation execution is done according to the following order of precedence:

  1. Paranthesis : innermost executed first
  2. Exponentiation
  3. Multiplication, division
  4. Addition , subtraction

So you can say, MATLAB  can be used as a calculator, where you can type the command or mathematical expression in the command window and execute the command by pressing the enter key, and you will get the answer directly as in the examples below:

>> 6+10/2
ans =
11

>> (6+10)/2
ans =
8

>> 4+5/6+8
ans =
12.8333

>> 5-(0.567)^3/(10*4)+0.88^6/(4*5*6*6)…
-(23)^0.5/(563*5)-100
ans =
-95.0056

Now we have seen the command windows and how do to arithmetic operations. It is also good to know about the Display Format used when displaying the results of the executed commands.

It will be covered in the next post. CLICK HERE

Leave a Reply

You must be logged in to post a comment.