← Course overviewFree lesson 1 of 3 · lesson 1 of 49Next lesson →

Unlock all 49 lessons of Matlab and Simulink BasicsFull course ₹40,000 · paid

Price & syllabus
Free lesson · 22 min · no payment

MATLAB Workspace, Variables, Data Types and Structures

A free lesson from Skill-Lync's Matlab and Simulink Basics course, on Grow by Skill-Lync · Last updated 16 Nov 2026 · Session: “MATLAB and Simulink Basics Language Fundamentals and Programming”

What will you learn in this free Matlab and Simulink Basics lesson?

The instructor introduces the MATLAB command window and workspace, then shows variables, a row vector built from powers of x equal to 5, and transposing it. The lesson covers double and single precision, NaN, character and string arrays, the whos command, structures and a first look at cell arrays.

  • Command window and workspace basics
  • Row vectors, matrices and transpose
  • Double versus single precision and NaN
  • Character arrays, strings and structures

What comes after lesson 1?

The next free lesson is lesson 2, “MATLAB Cell Arrays, If Statements, Loops and User Input” (20 min). Later in Skill-Lync's Matlab and Simulink Basics course (paid): lesson 4, MATLAB Demo and Workspace Management; lesson 5, MATLAB and Simulink Basics; lesson 6, Programming and Graphics in MATLAB. The full course has 49 lessons (17 h 10 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.

Welcome to MATLAB and Simulink Basics Week 1 Training, Language Fundamentals and Programming. Introduction to the course. The course is beneficial for those students and engineers interested in model-based system engineering, that is, design, analysis, development, and test. As the industry is aware of MATLAB and Simulink toolchain, it prefers the students or engineers with this training to speed up their design, analysis, development, and test cycle. At the end of this course, students will learn how to use MATLAB and Simulink for developing models and simulations. The challenge problems and mini-projects will help to develop their working knowledge of MATLAB and Simulink environment.

The projects will further help to strengthen their knowledge about the toolset. Skills required. Below is a list of skills required to take this course. Basic engineering, mathematics, and statistics. Knowledge of any programming language such as C, C++, or Python. And it would be beneficial to have knowledge of control systems, but it is not mandatory. Table of contents. During week one training, we'll go over workspace, variables, data types, loops, and conditional statements, inputs, inputs, and outputs, loading and saving data, followed by MATLAB demonstration of all of the above.

So they are the same learning objectives, what were listed in the previous slide. So we'll start with workspace. What is a workspace? So when you bring up MATLAB, it brings up a few windows. We will go over all elements of MATLAB environment in a detailed fashion as part of the demo toward the end of week one training. But to begin with, what I'm showing on the right is the MATLAB command window. So the command window is an interface of MATLAB that helps users to create workspace, basically.

That's why it's called workspace. So after launching MATLAB, one will see the command window that's shown on the right. So workspace, like I said, is the working environment of MATLAB. So in workspace, variables can be created and updated. Scripts and functions can be created and executed. Now we will go into the details of variables, what variables are. As you're all engineers or mathematicians, you would know what variables are all about. So in MATLAB, what's shown on the right is the command window, where the greater than, greater than sign is MATLAB prompt.

So when you bring up MATLAB in command window, that's what you would see. So it allows users to create variables, like I said before. So here, this is a quick demonstration of what has been done. So a variable X is set to 5 in the workspace. So once a variable X is defined, other variables can be defined as functions of X. For example, Y is defined as X to the power 2, that is X squared, plus 5 times X, plus 6. Any command, if it's terminated with a semicolon, it would not echo the value of that variable in the workspace.

If it's not, if the command is not terminated with a semicolon, then MATLAB will echo the variable and its value, as shown. So for example, X, if we just enter X without a semicolon, X, it's echoing the value of X, which in this case is 5. Similarly, Y, if you enter Y and do not enter a semicolon to terminate, then it will return the value of Y, which here in this case is 56. Because X is 5, X squared is 25, 5 times X is another 25.

So that's a total of 50, plus 6, 56. And MATLAB has another function called WHO, WHO. So when you enter WHO, it will return the variables in the workspace. So far, we have created variables X and Y. So when we enter WHO, command WHO, it will return the variables. It will list the variables that are in the workspace. So basically, what I'm trying to say on this slide is the workspace lends itself to the creation of variables. An example is shown on the right in the command window.

X is set to 5. Y is defined as a quadratic function of X. And then the value of Y should be 56 from the way X is set. The WHO, WHO, command, returns the variables in the workspace. So MATLAB, unlike other programming environments, it is an interpreter-based. So when someone types a command, it will interpret. So there is an underlying engine called MATLAB engine, which understands all these functions. I mean, early on, MATLAB was built on Fortran way back when. You know, in 1984, when MathWorks started developing MATLAB product.

So initially, the underlying engine was all developed in Fortran. But subsequently, C, C++ languages have evolved. And then MATLAB has adopted C and C++ to be their basic engine. So we already talked about what happens when a command is not terminated with a semicolon. So far, we have defined scalar variables, X and Y. But MATLAB environment also allows definition of vectors and matrices. Typically, vectors are denoted by lowercase letters, while matrices are represented by uppercase letters. So in this example, variable V is defined to be a row vector with four elements.

Each element is defined to be a function of X, as shown on the right. The first element of row vector V is simply X. The second element is defined as X squared. The third element is defined as X cubed. And the fourth element is defined as X to the power 4. So when you enter X, it echoes value 5. When you enter V, it echoes values of each element in that matrix, or vector in this case. So V is set to 5, 25, 125, and 6, 25.

As we have seen above, how the row vector V was defined. And it makes sense for when X is 5, the individual elements of XX squared, X cubed, and X to the power 4 will end up in giving a row vector with elements of 5, 25, 125, and 6, 25. So the variable V followed by a transpose, basically in MATLAB, it transposes the row vector. So what we are seeing here is when you enter V transpose, the answer becomes the transposed vector. Now it becomes a column vector with elements 5, 25, 125, and 6, 25.

So basically, what I have just said is explained on this slide. We continue on. We also talked about transposing a vector. Then we'll come to defining a matrix. So in this particular matrix, again, we have set X to 5. And one interesting thing with matrices is to tell MATLAB that a particular row ends, we have to use a semicolon. So that's how matrix M is built. The first row of matrix M with the elements X, 2 times X, and 3 times X, followed by a semicolon, what we are saying is that the first row has ended and the second row is starting.

So the second row has elements of 4 times X, 5 times X, 6 times X. The third row has 7 times X, 8 times X, and 9 times X. So with X set to 5, we built a matrix with those definitions. We'll end up in giving us a matrix with 5, 10, 15 on the first row, 20, 25, 30 on the second row, 35, 40, and 45 on the third row. Again, when we transpose the matrix M with an apostrophe, we get the transposed matrix, which is obvious from the answer.

With the first row of M becoming first column of M prime, we can call it prime. Prime and apostrophe are interchangeable in MATLAB. So similarly, second row has become second column, third row has become third column. Now, in the example shown on the right, we have created a square matrix. Square matrix with three columns and three rows. But MATLAB also allows rectangular and sparse matrices. You know, well, let's start with rectangular matrices. You know, square is one where you have the same number of columns and rows.

On the other hand, rectangular matrices will have unequal rows and columns. That's what basically what a rectangular matrix is all about. So maybe I'm not sure if I'm showing an example. Rectangular matrices, but we will see. Well, maybe we can do that during the demo. Now, the third element is data types. So, MATLAB has multiple data types. You know, when a variable is defined in the workspace as, by default, the variable is defined to be a double precision number. A double precision number takes 8 bytes of memory, which is basically 64 bits of the number.

Now, a single precision number only takes 4 bytes with 32 bits. So, why the size matters? I mean, if you have just a handful of variables, really, it doesn't matter. But in a typical simulation, you know, if it's an aircraft simulation, there are thousands and thousands of variables that describe multiple things in an aircraft simulation. So, it matters how much memory we allocate for each variable. I mean, MATLAB is residing within the Windows environment. So, MATLAB has predefined memory. It's part of the RAM allocated to run the application and then to create variables and run simulations.

But there is a limit to how much memory you can have. It's not unlimited. Also, MATLAB is known to use the hard disk space called virtual memory. But one needs to do the setting before you launch MATLAB. I will not go into virtual memory at the moment. So, it becomes critical to use memory sparingly. You know, some variables, you know, that take only binary values, like 0 or 1, you don't have to have 8 bytes set aside, 64 bits, because it's just a value, just one value, 0 and 1.

And it's not even signed. So, on the other hand, let us say for an aircraft simulation, you are trying to simulate the vehicle, an ascending vehicle, from takeoff to altitudes like 30,000 feet, 50,000 feet. So, 50,000 is a large number. So, I mean, depending on how many decimals of 50,000 and on top of 50,000 you want to use, there comes the question of precision. So, double precision, single precision. We'll also go over quickly on other data types that are available in MATLAB for users. So, one other thing is MATLAB also has utilities to convert variables from one type to another type.

What's shown on the right is one such example. So, X double is set to 5. By default, it's a double precision number. And in order to get X single, there's a utility called single, which takes an input value and then converts it into a single precision number. Down below, you would see the distinction. So, X double is a one-by-one element with a, you know, matrix-based, MATLAB is matrix-based. So, everything is a one-by-one, you know, number of rows, number of columns kind of a deal. So, X double takes 8 bytes of memory, and it belongs to double class.

X single, on the other hand, since we have converted using the single utility, into a single precision number. So, that became a single precision number belonging to single class with only 4 bytes of memory space taken. So, we talked about who before. Who command shows the variables that are in the workspace. Also shows the size, number of bytes allocated for each variable, and the class they belong. So, this is a quick list of data types. This MATLAB has inherently available or made available to the users.

There's a single double precision number system that we talked about. There is an int8 slash int16 data type. There are 8-bit signed integer and 16-bit signed integers, respectively. There is also a 32, int32, int64 that's available. Also, there are uint8 and uint16 data types available. Uint is unsigned integer. Again, 8-bit and 16-bit integers that users can create in MATLAB. Similarly, MATLAB has uint32 and uint64. Also, MATLAB has functions to typecast. Cast and typecast. They allow type change from one data type to the other. So, MATLAB has the functions that are shown on this slide to query the data type.

For example, if a variable is an integer, you can check with is integer utility. It's a function that takes one argument. There is an is float utility that will check if an input variable is a float. Floating point number, that is, is numeric, is another utility that will check if the input is a numerical value or an alpha numeric value, like an ASCII number. You know, ASCII numbers have all kinds of characters. What I'm trying to say is if it's a numerical value or a string, I should say.

Is numeric or non-numeric, basically. Then, they also have a utility called is real. Is real, I know we haven't talked about real and imaginary numbers. You know, as you might have come across in engineering, real, real, in any, an imaginary number will have a real part and an imaginary part. You know, typically, A plus JB or IB, where I or J is the, is the letter that indicates the part that it's multiplying is the imaginary part of a complex number. So, we are not going to go into the details of their applications in electrical engineering.

It's quite a bit of an application for complex numbers. So, we'll, we'll, we'll not dwell on it at the moment. But the is real function essentially checks if the input argument is a real number or a complex number. So, there, there are a few more functions that are available in MATLAB to check if a number is finite or not. Is finite is the function. Similarly, is INF to check if the number is infinity or not. Typically, you get an infinity anytime you have a zero division going on.

If it's a zero over zero, then that's a, that's not a number. I mean, it's not defined. In MATLAB, a number that's not defined is called NAN, not a number, basically. So, you can check if a number is a NAN or, or, or not with ease NAN utility. So, MATLAB also supports character and string data types. I mean, so far we have talked about numerical values with the double precision, single precision, and other types. So, MATLAB also supports string data types. So, a string needs to be embedded within single quotes.

That's how you are telling MATLAB that, hey, this is a string. You know, here, for example, city as a character array is defined, you know, a Bangalore with single quotes is defined as a, as a variable called city as a character array. And city as a string array, the same Bangalore is defined with the double quotes. We'll see what the difference is. So, so here it says a character array is an array of characters. That's what it is. Single quotes are used to define a character array.

So, when you enter whose, W-H-O-S, the who will only list the variables. But with an S, whose, W-H-O-S, will show its size, bytes, and class in addition to the variable name. So, the character array that we defined above is of size 1 by 9. So, it has 9 elements taking 18 bytes. And it belongs to a car class, C-H-A-R, car or car. On the other hand, the string array, we defined Bangalore to be a string array using double quotes. It is just 1 by 1 size.

But it has taken 166 bytes. And it belongs to a string class. So, a string array is an array of strings. And double quotes are used to define a string array. You know, we already said that. And note the difference between a string array and a character array in terms of the memory space it takes. So, MATLAB also supports another data type called structure. Those who have programmed in C would know what a structure is. It's similar to, MATLAB structure is similar to C structure. So, where one can define multiple fields.

Multiple fields become part of the structure. I mean, in this example, on the right, we are trying to come up with a class. Average marks structure with the marks obtained by the students. I mean, here we are saying average marks. So average marks obtained by the students in each subject. You know, mathematics, the average mark was 85. In physics, it was 76. In chemistry, it was 71. So we created a class average mark structure to contain the subject field and marks field, so to speak. So when you enter class average marks dot mathematics, it will return the value stored for mathematics. So the 85.0 is associated with mathematics, 76.0 is associated with physics, 71.0 is associated with chemistry.

So the class average marks dot physics will return 76.0. And the class average marks dot chemistry returns 71.0. So that is how the data type structure works in MATLAB. We already talked about that. So MATLAB has one other data type called cell array. You know, we talked about the structure. The cell array, the data is embedded within braces. I mean, that's so far we haven't used the braces. So, you know, for cell arrays, we have to use braces. I mean, the distinction between cell arrays and any other data type is the fact that any other data type would support, especially when you want to create a matrix, you cannot have numbers and strings in the same matrix.

We'll discuss cell arrays, you know, in much more detail.

Want the rest of Matlab and Simulink Basics?

Get the full course syllabus and fees.

The full course is paid (₹40,000). We'll send the syllabus and call you back within one working day.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Full course · paid

Unlock the full Matlab and Simulink Basics course

The remaining 46 lessons, mentor-reviewed projects and a certificate come with the paid course (₹40,000). Leave your details: we'll send the syllabus and fees and call you back.

Get the syllabus and fees

A counsellor calls you back within one working day.

By submitting you agree to our Terms and Privacy Policy.

Grow by Skill-Lync · free lesson

Start watching

Free, no payment. Leave your details once and every free lesson on Grow plays straight away. A Skill-Lync counsellor may call you about the full Matlab and Simulink Basics course.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.