Welcome to MATLAB TUTORIAL -1 (Lecture -3)
In first 2 lectures we discusses very basic prerequisites for Matlab learning. If you haven't gone through them I would suggest to have an eye on them before moving into this tutorial. Here are the links for Lecture- 1 and Lecture- 2 .
Before starting this tutorial please get MATLAB software installed into your PC / Laptop there are many tutorials available on internet teaching us how to do so. I would be using MATLAB 2018 but you can use any version as per your availability.
As by now we all have basic idea about Matrix and its very basic operations. So lets get started :
So, firstly run your MATLAB software.
So, now I would brief you up about the interface, its gonna be very simple and easy.
We can see there are four main white space blocks available these are:
1. Current Folder
2. Workspace
3. Editor
4. Command Window
1. Current Folder: This space just shows the data of folder in which our MATLAB software is targeting. The files (audio files and picture files) which we would be uploading or accessing into our MATLAB software should be available at this folder. And the address bar shown just above the current folder space and editor space is our address bar which tells us address of folder on which MATLAB is targeting.
2. Workspace: It is the space which keeps a note on our command window and one can get a basic outline of what is inside our code from just having a look at workspace. It makes our work a lot more easier when we deal with large programs or during troubleshoot process.
3. Editor : In editor we write functions/ scripts/ codes it is more linked to our command window as whatsoever we may define here we will execute it in command window. So editor is much like a code space.
4. Command Window: Here the main compilation and execution process takes place. Whatever we type here and press enter is executed at the same time. It is the most used space of MATLAB.
MATLAB codes are very simple and easy to execute. I won't be going into much theoretical explanation of interface as rest of the things we would be learning on the go with the flow.
To assign value to variable is as easy as saying hello to a friend.
Lets suppose we want to assign integer value 5 to x
To do so in command window type :
x = 5
Press enter that is it, we have successfully assigned a value to variable.
You should be getting this as the final result, now notice workspace and command window. In workspace x (Name) and 5 (value) has started to appear. This is the main work of workspace it will keep on telling what is going on in our program. Now coming to command window as soon as we will press enter after typing x = 5 , it will revert us back saying x = 5, which is also termed as output of our command.
Inserting a Matrix :
We know that matrix have rows and columns, and are of M x N order
So, lets suppose we want to insert matrix A = | 1 2 |
| 3 4 |
Just type this in command window:
A= [ 1 , 2 ; 3 , 4 ]
Brackets[] indicate matrix and semicolon indicate next row , whereas commas are optional to use, we can even use just space between element but using semicolon is very important as it makes the software aware about next row.
So, here is how it looks like:
Just, notice the change on workspace also.
Now try inserting a [1 x 3 ] matrix (that is row matrix) B = [1 2 3]
Again simply, type in the command :
B = [1 , 2 , 3]
That is it.
Now try inserting a [3 x 1 ] matrix (that is column matrix) C = | 1 |
In first 2 lectures we discusses very basic prerequisites for Matlab learning. If you haven't gone through them I would suggest to have an eye on them before moving into this tutorial. Here are the links for Lecture- 1 and Lecture- 2 .
Before starting this tutorial please get MATLAB software installed into your PC / Laptop there are many tutorials available on internet teaching us how to do so. I would be using MATLAB 2018 but you can use any version as per your availability.
As by now we all have basic idea about Matrix and its very basic operations. So lets get started :
So, firstly run your MATLAB software.
So, now I would brief you up about the interface, its gonna be very simple and easy.
We can see there are four main white space blocks available these are:
1. Current Folder
2. Workspace
3. Editor
4. Command Window
1. Current Folder: This space just shows the data of folder in which our MATLAB software is targeting. The files (audio files and picture files) which we would be uploading or accessing into our MATLAB software should be available at this folder. And the address bar shown just above the current folder space and editor space is our address bar which tells us address of folder on which MATLAB is targeting.
2. Workspace: It is the space which keeps a note on our command window and one can get a basic outline of what is inside our code from just having a look at workspace. It makes our work a lot more easier when we deal with large programs or during troubleshoot process.
3. Editor : In editor we write functions/ scripts/ codes it is more linked to our command window as whatsoever we may define here we will execute it in command window. So editor is much like a code space.
4. Command Window: Here the main compilation and execution process takes place. Whatever we type here and press enter is executed at the same time. It is the most used space of MATLAB.
MATLAB codes are very simple and easy to execute. I won't be going into much theoretical explanation of interface as rest of the things we would be learning on the go with the flow.
Assigning values to variables:
To assign value to variable is as easy as saying hello to a friend.
Lets suppose we want to assign integer value 5 to x
To do so in command window type :
x = 5
Press enter that is it, we have successfully assigned a value to variable.
You should be getting this as the final result, now notice workspace and command window. In workspace x (Name) and 5 (value) has started to appear. This is the main work of workspace it will keep on telling what is going on in our program. Now coming to command window as soon as we will press enter after typing x = 5 , it will revert us back saying x = 5, which is also termed as output of our command.
Inserting a Matrix :
We know that matrix have rows and columns, and are of M x N order
So, lets suppose we want to insert matrix A = | 1 2 |
| 3 4 |
Just type this in command window:
A= [ 1 , 2 ; 3 , 4 ]
Brackets[] indicate matrix and semicolon indicate next row , whereas commas are optional to use, we can even use just space between element but using semicolon is very important as it makes the software aware about next row.
So, here is how it looks like:
Just, notice the change on workspace also.
Now try inserting a [1 x 3 ] matrix (that is row matrix) B = [1 2 3]
Again simply, type in the command :
B = [1 , 2 , 3]
That is it.
Now try inserting a [3 x 1 ] matrix (that is column matrix) C = | 1 |
| 2 |
| 3 |
Command :
C = [ 1 ; 2 ; 3 ]
This row matrix and column matrix we tried to insert were just to clarify our row and column syntax difference.
Here is screenshot for both :
Use of Semicolon in last of command line:
If we do not use semicolon at the end of command line it would display result instantly after the last command execution.
If we use semicolon than last command is not published.
Notice the image below carefully:
I guess this would be enough for Matlab Introduction tutorial (Lecture- 3).
So stay tuned,
BYE BYE
Comments
Post a Comment