Unlock all 55 lessons of EV FundamentalsFull course ₹40,000 · paid
Introduction to MATLAB for EV Engineers
A free lesson from Skill-Lync's EV Fundamentals course, on Grow by Skill-Lync · Last updated 15 Nov 2026 · Session: “Introduction to Matlab”
What will you learn in this free MATLAB and Simulink lesson?
Why EV makers simulate in MATLAB and Simulink before buying and testing hardware, then a hands-on tour of MATLAB: the command window, workspace and editor, variables, vectors and arrays, indexing, and everyday commands such as disp and who for checking what is stored in the workspace.
- Why simulation saves cost when developing an electric vehicle
- The MATLAB windows and what each one is for
- Declaring variables, vectors and arrays, and indexing into them
- Useful commands for displaying values and listing workspace variables
What comes after lesson 1?
The next free lesson is lesson 2, “MATLAB Programming: Conditions, Loops and Functions” (44 min). Later in Skill-Lync's EV Fundamentals course (paid): lesson 4, Simscape; lesson 5, Simulink Demo; lesson 6, Stateflow. The full course has 55 lessons (12 h 45 min of video); see the course overview or its price and syllabus.
Lesson transcript
Machine transcript of the lesson audio (lightly cleaned). Technical terms may contain errors; the video is the reference.
Hi, this is Rajkumar and now we are going to learn about the MATLAB and Simulink. The MATLAB is a software which was invented by Cleve Moler in the year of 1960s in order to solve the simple matrices. Let us understand why we are going to learn about this MATLAB. Even though this MATLAB is being invented for solving the simple matrices, later on it has been grown like anything and at present, most of the industries are using this MATLAB and Simulink softwares. Now, for example, if you are going to take the automotive industries, for manufacturing the EV, they are using this MATLAB and Simulink.
So, for example, if you are going to manufacture an EV, what you need to do, you have to buy the components and assemble it and test it. Suppose that testing gets failed and you are not getting the expected result, you need to rebuy the component and the process you have to repeat again and again. So, it involves lots of investments. So, those investments can be avoided if we are going to use the MATLAB and Simulink software. So, using simulation, you can be able to create the electric vehicle easily and you can be able to replace the parts very easily without any cost investment.
So, that is the reason why we are learning this MATLAB and Simulink. And moreover, this is a skill which is being expected from all the engineers by the industries. Now, let us see about the MATLAB alone. So, actually, the MATLAB is a kind of programming which we can be able to do in order to solve linear equation, algebraic equation and differential equation. And apart from that, we can be able to create the programs which can be suitable for the embedders, software and control systems. So, those programs can be made using the MATLAB code.
So, let us see how we can be able to do the MATLAB installation. Now, let us see how we can be able to get the MATLAB software from online. So, what you need to do is you have to go to any one browser in your desktop and you need to type MathWorks. So, if you are going to type MathWorks, you will get the link to the MathWorks site. So, you have to click on the link. Then, what you need to do is you need to sign in to that account.
So, here you will have the option for logging in. So, in that, if you are having the account in the MATWorks, so you can directly sign in to that account. Otherwise, you can create a new one by clicking into this create one. So, since I am having the account already, I am just going to log in into my account. Now, okay, once I log in to my account, so here I am having the option like get a trial. I can click on this get a trial.
I will have the option to get trial version for 30 days. Okay. So, this trial version, either I can be able to use it in the online mode or else I can be able to download and install the MATLAB to my PC. So, if I click this option, I can be able to use the MATLAB in the online itself. Those who are having low configuration in your PC, you can click on this and you can use online. Or else, if you are having a very good configuration in your PC or laptop, you can click this install.
It will take you to the new tab. So, as you can able to see here, there is an option for download. So, by default, it will be like download for Windows. Suppose, if you are using Mac or Linux OS, so that you can be able to select your operating systems from here. And after selecting the operating system, you can click over the download for that operating system. So, if I click this download, immediately the download will start. Okay. Once the download gets complete, you can double click this file and install the MATLAB easily.
So, now we have understood the installation procedure and how we can be able to get the MATLAB from MathWorks. Let us see what we are going to learn from this course. From this course, we are going to learn how we can be able to use the MATLAB and what are the different windows which are available in the MATLAB. And most of the programming have multiple datas during its processing. So, how we can be able to store those datas means using the vectors and matrices only it is possible.
So, for that purpose, we are going to learn about the vectors and matrices. Then followed by that, we are going to learn about the condition statement and looping statements. In order to do the programming, the condition statement and looping statements were mandatory. And during the programming, we used to call few set of statements very often. So, in order to call those few set of statements very often, we should be aware of how we can be able to create the functions. So, here we are going to learn about how we can be able to create the functions.
And the process data can be shown to the user in a user interface manner with some graphical effects. So, that is possible with the help of the plot commands. So, here we are going to learn about the plots. How we can be able to do the plots from the data which we have obtained from the programming. Let's see what are the things which we are going to get from this course. So, if we learn this course, we will be aware of what are the different commands which are available in the MATLAB.
And how we can be able to use the condition statement and the looping statements. Using the condition statement and looping statement, how it is possible for us to create the programmings. That knowledge will be obtained from this. And we can be able to understand about the functions. How we can be able to create the functions using the MATLAB. And how we can be able to process the data using the plot commands. So, these are the things which we will learn from this course. So, let's see what is the MATLAB is.
So, MATLAB is a short form of matrix laboratory. So, the matrix, since it is being used for solving the matrices in the early time, it have got the name like MATLAB. Now, what does this MATLAB have in the sense, it have the programming window through which we can able to do the programming to create any sort of models. And that models can be analyzed and tested very easily and it can be modified as per the user requirement. Let us see what are the different windows which are there in the MATLAB.
So, if you double-click the MATLAB icon, it will open the home screen of the MATLAB. So, this is the home screen which you are seeing right now. So, here there are multiple windows. Let us understand about each windows. So, the first window you can able to see over here is nothing but the directory window. So, this is the directory window which will give you an idea about what are the files which are there in the present directory and in which directory your program will get stored.
Okay. And this is going to be the editor window. And what is the purpose of this editor window in the sense, if you want to store your program permanently in the computer, you can type the programs in the editor window and you can save that. So, if you save that in the editor window, that file will be saved with the extension of .m. And when you are reopening the MATLAB, you can be able to open the file and you can run the program directly without any typing.
Suppose, if you want to type the program and execute it instantaneously, you can use the command window. Okay. So, this is the command window. In that, you can be able to type any program. And moreover, this command window, you can use just like an arithmetic calculator. For example, I will show you 2 plus 5. So, if I am going to simply type the 2 plus 5, the answer will be reflected. And this answer is getting stored temporarily over another window called workspace window. So, this is the window which will store the values which are entered over the command window in a temporary basis.
So, if you close the MATLAB and reopen the MATLAB, this will be erased. Okay. So, that is the specialty of this workspace window. Now, let us understand how we can able to create array of data. So, for understanding what we are going to do, we are going to take one table. So, that table I have already created using an Excel sheet. So, I am just clicking the open and in that, I am just changing the file extensions to all files. So, I am having the file, Excel file named drive cycles.
So, I am just double clicking the drive cycles. Let us see what is mean by the drive cycles. At first, the drive cycles are nothing but the driving pattern which the driver used to drive a vehicle. So, the vehicles were driven by different drivers. And for all kind of drivers, the vehicle should be able to adopt. As well as it should work properly. So in order to understand that, what usually being done by the company is in the sense, they used to have some standard drive cycles and using those standard drive cycles, they will test the vehicle's performance.
So here I have created my own drive cycle with random datas. So let's see, let's import these drive cycles to the workspace. How you can be able to import means, if you directly open the Excel sheet, it will automatically select. By any chance, if the selection process is not being done, then you can select it manually and you can click on this import selection. So if you click this import selection once, it will reflect in the workspace window. As you can be able to see, in the workspace window, it is showing like drive cycles.
So if I'm going to double-click this drive cycles, it will open. So here, as you can able to see, this is going to be between the time and velocity. So the plot is going to be, the datas are going to be time and velocity with respect to time, how the velocity is getting varied. So that is what the drive cycle is. I'm going to select these things by clicking over this. So if you simply click over here in the first column, in the first cell, it will be automatically selected.
And by holding the shift and left key, you can be able to select the datas completely. So afterwards, what you need to do is, you can go to the plots. In the plots, there is multiple options to do the plots. So plots are nothing but the graphical representation. So you can use normal plotting or else you can use area plot, bar plot, scatter, pie, histogram, and some more plots are there. So for simplicity, I'm going to take the normal plot command and just clicking on the plot.
So as you can able to see, a new window has been opened and this window is named as the figure window. So by default, it will have the name of figure one. Now, this figure window have plotted the values of the time and velocity, which I have imported from the Excel sheet. So this is how we can able to plot the different datas from the array of values. Okay, I hope now you understood what are the different windows which are there in the MATLAB and its purpose.
Now, let's see what is the uniqueness of the MATLAB. So if you are going to see the uniqueness in the sense, here the MATLAB used to operate as an interpreter. So we all might have heard about the word compiler, but interpreter may be a new word, right? So let's see what is mean with the compiler and what is mean with the interpreter. So you pupils might have heard about the language like C, right? So C is a very basic language which can be able to run only when we have completely written the program because it need to be compiled at first.
What does the compiling mean in the sense? The complete set of programs has to be built. Then only we can able to analyze the program. So that is what the compiler is. Whereas in the case of interpreter in the sense, we can able to run the program line by line. So if I'm going to type a single line, the single line can be analyzed and can be executed at the same instant. That is what the interpreter is. OK, so when you're going to compare the MATLAB with the pre-existing C language, the MATLAB is more flexible since the MATLAB is going to be an interpreter, whereas the C language is going to be a compiler one.
OK, so here the MATLAB is going to be completely flexible. OK, and moreover, what is the other benefit in the sense? It can be able to run in any sort of platforms. So we can be able to run the MATLAB in any platforms easily. We can be able to create the apps. We can be able to create web pages or else we can be able to create any sort of codings like embedded programs and other things we can be able to create using the MATLAB. So that is possible in the case of the MATLAB.
That is the uniqueness of the MATLAB. Now let's see the different commands which are there in the MATLAB. Let us understand the different commands which are used in the MATLAB. OK, now we'll start with the simple concept, how we can able to define a variable and how we can able to assign the value to the variable. Now, for example, I'm just taking a variable A. OK, and for this variable A, I'm going to assign a value 3. OK, and if I'm going to press enter directly, it will show the value of that variable immediately in the command window.
So, suppose I don't want to store the value. I don't want to show the value immediately, but I want to save it. By that time, what I can able to do, I can give a termination operator. So, this is what we call this end of the statement operator. So, end of the statement operator is nothing but a normal colon. So, if I'm going to give a semicolon over there, and if I'm going to press enter, B equal to 2. So, the 2 value will be stored in the B, and as you can able to see over here in the workspace, the B value is being assigned with the value of 2.
OK, it is stored, but it is not showing immediately in the command window. So, this is how we can be able to assign values to a variable. Now, we can be able to perform arithmetic operations over here. So, for that, let us have an example. Suppose, if I want to multiply A and B. So, see, I have given C equal to A multiplied with B with the asterisk symbol. So, this is the asterisk symbol. Using that asterisk symbol, I have multiplied the A and B, but it is not showing the value of the C.
But, the same C value is being updated over here in the workspace as 6. So, 3 into 2, which is going to be 6, and that 6 value is being stored over here. OK, now, let us see how or in which way we can be able to get the input from the user. If I want to get an input from the user, I can write a command like input. So, here, I am just declaring a variable X. And for that variable X, I am going to get a value from the user.
So, I am just using the input command with input. And followed by that, I have to open a C bracket. And inside the C bracket, I have to open a single quotes. So, whatever content which you are going to give inside these single quotes will not be compiled as a command. It will be taken as a characters. OK, so characters are nothing but strings or certain alphabets. That's it. OK, that is how it will be considered. Now, I am just asking, enter any number. OK, and I have to close the single quotes and I have to close the C bracket.
And if I press enter, see, it is asking enter any number. So, whatever things which I have given over here, it will reflect. OK, now what I am going to do, I am going to give a value for this. So, I am going to give a value of 8 and press enter. Immediately, the X is being assigned with 8. Actually, it is showing only here as enter any number. But that enter any number is being used with the input command for assigning value to the X.
So, the X is being assigned with the value of 8. And as you can able to see over here in the workspace, it is there as 8. Suppose, I want to get a value from the workspace. What I can able to do, I can use this command. So, if I am going to use this of X and press enter, it will show the value of the X. And similarly, if I am going to use some other value. For example, I am going to say I want to display the B.
So, it will show the B value. So, B value is being stored as 2, right? So, that B value is being shown over here as 2. OK. So, this is how the display command will be working. Suppose, I want to know what are the different variables which I have stored inside the workspace. So, that what I can able to do, I can use a command called WHO. So, if I type WHO and press enter, it will show all the variables which are stored inside the workspace.
OK. And if I want to know which type of variable it is and what is the size of the each variable means, I have to use a different command called WHO. Yes. So, if I am going to use whose, it will show me what is the size of each variable. Like A, it is going to be 8 and which type of class it is going to be. So, likewise, it will show for all variables. So, all the variables will be shown over here. It's data type.
So, the details will be shown over here with the host command. OK. Suppose, I want... To clear all the data which are there in the command window. What I can able to do, I can type a command called CLC. So the CLC stands for clear screen of command window. Okay. So if I type CLC and press enter, see my command window is completely empty. It doesn't have any data. And if I'm going to use clear all. All. If I'm going to use the clear all command, it will clear all the datas which are there in the workspace window. So I'm going to press enter. See all the datas which are there in the workspace have gone. Right. So the clear all command will clear all the datas which are there in the workspace. Okay.
and if i'm going to use close all so if i'm going to use the close all command it will close all the windows which are being popped up from the matlab like the figure windows so if i have open n number of figure windows i can use the close all command and by using the close all command i can close it okay so if you press close all command it will close whatever the figure windows which are currently open okay so i'm just typing the clc again and the last one is the exit so if i'm going to type exit command it will close the matlab without pressing this exit button i can able to close the matlab just by typing the exit command okay so if i type exit and press enter it will close let us understand about vectors at first let's see what is mean by the vectors vectors are nothing but the collection of datas of same data types which are going to share a same name or common name just like an array okay now why we need to have the vectors means most of the cases if you are going to solve a linear equation or any one equation which is going to be continuously varying in that case what will happen it will produce multiple datas in a sequential manner and if you want to store such datas you need to know about the vectors okay so for that purpose only we are going to know about the vectors at first so i'm going to take a variable b and for this variable if i want to create it as a vector what i have to do i have to open a square bracket so followed by the square bracket i have to i can type my variables with one single space so 4 space 6 space 8 2 so i have typed 4 variables in this vector so if you want to know if you want to make the program to know that it is over i have to close the square bracket and followed by that i have to use the end of the statement that is a semicolon so if you press enter these four values are being stored to the v right as you can able to see this workspace 4 6 8 and 2 were stored here okay so if i type v and press enter it will show all the values in a single row so this is what we called as row vector so if i'm going to say it is a row vector i can able to create the column vector too let's see how we can able to create the column vector in the same way how we have created the row vector i'm just opening a square bracket inside the square bracket i'm just giving a value after the value what i have to do i have to put a semicolon then followed by that i have to enter one more semicolon after each value so if i'm having four values i can give four uh three semicolons after the first three values and the last semicolon at the end of the statement so if i press enter this the v1 will be updated with this value and i just want to know whether it is a column vector or a row vector so i'm just typing v1 over here and if i press enter as you can able to see all the values are being stored in a single column earlier it was in the single row over here it is a single column so the that first one v is going to be the row vector and v1 is going to be the column vector okay now let us see how we can able to create the matrices so i'm just taking i'm just going to clear the screen at first so i'm just using the command clc by clc i have cleared the screen and i'm going to create a variable m for creating the matrix so m which i'm going to give values for the first row so i'm just opening a square bracket then followed by that i'm just giving three elements for the first row and after the three elements i'm just including one semicolon then followed by that i'm going to include three more elements and i'm including a semicolon then finally i'm giving the third row and i'm just closing the square bracket and pressing enter so now the m value that is this m variable is being updated with the values which i have given in the same format as you can able to see the uh workspace it is being updated right now let's see whether it is being stored in the matrix format or not so for that i'm just going to type m and press enter so if i press enter it is showing a matrix right so this is one of the way which which we can able to create the matrices and let us see what are the other ways for creating the matrix as well as vectors okay so for that i'm just clearing my screen again and let me show you how we can able to create the vectors in other methodologies so i'm just taking a variable of b and for the b i'm just using the square bracket again but this time i'm not going to give the values one after another by leaving a space instead of that what i'm going to give i'm going to use the starting value and followed by the starting value i'm just using a colon and i'm going to give the deviation with which it is going to make the value change and i'm going to give one more colon and i'm going to give the n value okay see and i'm closing this vector now what does this means in the sense 0 to 20 it is going to be the range within this 0 to 20 the variables has to be created for every two deviations so first 0 then 2 then 4 likewise it will create for every two deviations let's see how it is coming as i have told you it is coming like this see 0 2 then 2 plus 2 4 then 4 plus 2 6 then 6 plus 2 8 likewise it is created up to 20 so this is another methodology with which we can be able to create the vector okay now let me create one more vector just like this 0 2 instead of 0 to 2 i'm just taking 0 1 to 10 okay so with one deviation if you are going to give one it will take the one value as it is if you don't give the one and if you're going to simply give 0 to 10 also it will go it will take the same value only i'll show you how it will used to do so if i'm going to press c what i'm getting 0 to 10 right so same way i'm i'll assign one more way methodology so 0 colon then 10 so if i give like this it will show the same result so if i'm going to give the deviation as one or if i'm not giving the deviation by default it will take this one okay now i'm having the vectors like v which is having the range of 0 to 20 and c 0 to 10 with a with a difference of 1 whereas 0 to 20 with a difference of 2 it is there right so let's see how we can able to do the multiplication okay so i'm just taking a value e so there is a multiplication or addition or subtraction if you're going to do with respect to the vector what you need to do is one the major thing which you have to keep it in your mind is followed by the variable you have to put a dot okay then followed by the dot you can use that arithmetic operator then you can use the next variable okay and one more thing you have to keep it in your mind when you are doing the multiplication or addition or subtraction in the vector the values or the number of values which is there in the vector should be equal in numbers so if the b vector is going to have 10 values obviously c vector also should have 10 values only it should not have more or it should not have less okay so i'll show you the value of the e c e have created with the multiplied vector of b and the c so if i'm going to give this dot function it will take like each term of b has to be multiplied with each term of c so this dot operator has to be there when you are going to use the vector multiplication this same is applicable for the matrices also okay let us see one more example for solving the equation how it is possible okay so let me take one simple equation uh so i'm going to mention the equation and i don't want the equation to the equation to get executed So in that case, what I can able to do, I can comment it. How I can able to do the commenting? Commenting in the sense, things which will not get executed.
So I can able to comment like with the help of the percentage. So if I'm going to include the percentage and followed by that, whatever things which I'm going to type, it will not get executed in the command window. So 3x plus 4y plus 2z, which will be equal to 10. So if I'm going to take this one as an equation, this is going to be a normal equation. Similarly, I can take two more equations, 5x plus 9y plus 10z equal to 20. So I'm just taking one more equation, just like this, 9x plus 7y plus 10z equal to 30.
So now, if I want to solve this equation, what I can able to do is, I can able to convert this equation into matrix form easily. OK, so what I need to do is, I have to use a variable for the matrix and I can include the coefficients like 3, 4, 2. Then that is going to be the first row of elements. So I'm just including one semicolon, then followed by that. 5, 5, 9, 10. Then again, one semicolon, then 9, 7, 10. So these are the three equations, coefficients and have included like this.
And I created the matrix A. So the A matrix is created. And similarly, I can include the remaining things which are there in the right hand side to the B matrix. So 10, followed by the 10, the row is getting over. So I'm just including one semicolon, then followed by that 20, then semicolon, then 30. I'm just closing the bracket and including the semicolon. So likewise, I can able to create or convert the linear equations into matrix form. So if I convert the linear equation into the matrix form, I can easily solve this matrix and I can able to find out the value of the X, Y, Z easily.
Let me show you how I can able to find out the X, Y, Z. So for example, if I'm going to see X, if I want to find out the value means, I can apply inverse. So we know the formula called AX equal to B, right? AX equal to B is a thing which is known to us. So this AX equal to B, what we can able to do, we can able to write like X is equal to inverse of A, inverse of A multiplied with B.
Like this, we can able to enter. So this same methodology only I'm going to follow over here. So what I'm going to do, I'm just using a command called INV. So using that, I can able to find out the value of the X, Y, Z within a fraction of second. So it is possible for us to solve the linear equations using the MATLAB within a fraction of seconds. So this is how linear equation solving is being done in the MATLAB. OK, so I'm just clearing my screen again. Now what I'm going to do, I'm going to create a vector Z.
OK, and I'm here, I'm going to create a vector 1, 2, 3, 4, 5 with the 5 elements in the first row. OK, and 5 elements in the second row. I have created the vector. I just want to fetch only a specific value from this vector. What I have to do is Z for all. If I'm going to use the colon, it includes for all. And if I'm going to press enter, see, it is showing the second column alone. So let me show you the value of the Z. So this is the value of the Z.
So in the case of Z, the second column element is going to be only 2 and 7. So all the elements in second column is being shown over here. Suppose if you want to show all the elements which is there in the second row, what I have to do, same thing, 2, comma, colon. If I press enter, it will show all the elements which is there in the second row of the same vector. So this is what we used to call as vector indexing. So vector indexing is also possible in the case of MATLAB.
Why we need to do the vector indexing means vector is a collection of data, right? But if you want to fetch only a specific data, in that case, what you need to do, you have to go for the vector indexing. I hope now you have understood about the different ways of creating the vectors and how you can able to create the matrix and how you can able to solve the linear equation is in the matrix. Now we saw different commands which are being used in the MATLAB.
Let's have an overview about what we have seen. So in the commands, we have learned about the CLC, which will clear the command window, and CD to change the directory of the program whenever we require. And the semicolon has to be used in order to terminate the line or which can be stated as end of the statement. And if you want to get the input from the user, we can be able to use the input command. That way we can be able to get the input and store it to a variable.
And that stored value, if you want to get it over the command window, we can use the disk command so that we can be able to get the value in the command window. And using WHO and WHO is, we can be able to list down all the datas which is available in the workspace. And using the help command, it is possible for us to get any syntax of any commands from the MATLAB. And using global, we can be able to create a variable as global, and we can access in any programs.
And using clear all command, we can be able to clear the workspace. And using close all command, we can be able to close all the figures which is there in the MATLAB. And using quick and exit, we can be able to exit from the MATLAB. And these are the symbols which we have learned in the MATLAB. Let's see what are the things that we have learned from the MATLAB. Now, we learned what are the different windows which are available in the MATLAB, and what the purpose of each windows.
Then, we learned what is its uniqueness, how the MATLAB is getting varied from other languages. And we have learned about the different commands and its syntax, which is there in the MATLAB. And using those commands, how it is possible for us to create the simple, simple programs that also we have learned. And we learned about the vectors, how we can be able to create the vectors, how we can be able to create the arrays, and how we can be able to create the matrices. And in which way it is possible for us to do the indexing also.
So, these are the things which we have learned in this video. In the next video, let's learn about the conditional statement and looping statements. .