Command Window in MATLAB, basic commands in matlab, matlab command window, matlab basic commands

Hello, peeps! Welcome to another exciting tutorial on MATLAB in which we are discussing one of the most important windows of MATLAB that you are going to use the most. In the previous tutorial, we learned a lot about the basics of MATLAB and the different types of windows that are used in MATLAB and are present on the face of MATLAB when you launch it. There was a piece of interesting information about the basics of this fantastic development environment. This is the next step in the related tutorial in which we study the applications and workings of command windows in depth. Here is a glance at the topics that you are learning about today. 

  • How can you define the command window of MATLAB in detail?

  • What are some examples of commands related to online help?

  • How can you use the useful commands on MATLAB related to the variable?

  • Give the information about the commands related to the files, directories, and the PC that you are using. 

  • What are some examples of the type of equations that are solved in the command prompt?

Thus, let’s start learning.

Introduction to Command Window in MATLAB 

Recall that the command window is the basic window that is shown in the centre of the screen when you fire up your MATLAB, and here, the pre-defined commands are run in the easiest way by merely providing the command and values. If it seems to be normal right now, then maybe you have unclear programming skills because programmers know that in most languages, the commands and functions have to be defined first. 

Not only this, but the command window also performs another responsibility. In some programs, when we are using the edit window, the command window shows us the results and outputs of the calculations, if applicable. The usage of edit windows is not yet discussed in his tutorial, but you can understand that the command window shows us the numerical output and the command’s results when we allow it to do so. 

Using Command Window for Online Help

As we have said earlier, the command window is used for different purposes, and therefore, at the beginning, we are telling you about the different ways to seek official help from MATLAB if you are stuck in any situation and do not know how to tackle it. The good thing about MATLAB is that it provides you with the maximum information and helps in different ways and it is made for students. Therefore, it not only provides you with the terms of help but also defines them in the easiest way so the students may know where they have issues in the calculations. So let’s start the process of finding help in different ways in MATLAB. Just follow the steps given below:

  • Launch your MATLAB software. 

  • Go to the command prompt where the function catalogue is blinking. 

  • Start writing the following commands to check what they do.

  1. help

By writing this in your command window, you will get the list of the commands for which, MATLAB can help you by defining the introduction and codes of that particular command.

Command Window in MATLAB, basic commands in matlab, matlab command window, matlab basic commands

  1. helpdesk

It creates a helpdesk for you and directs you towards the MATLAB official page where you can report and find help regarding your issues. 

  1. help topic

This command provides you with help regarding a particular topic. Assume that you want to get help related to MATLAB's "help" command, which was also mentioned above. You can type "help" instead of "topic" in this command. You will get the details all the time. 

  1. helpwin

It is a special command that is used to get the help link and details in a separate window.

Command Window in MATLAB, basic commands in matlab, matlab command window, matlab basic commands

  1. lookfor string

This is an interesting command that is designed to provide you with help related to the strings that we will use in the codes. If you are new to this concept, skip it for now because you are going to learn about it in detail in the coming sessions.

  1. demo

It is one of the most amazing commands in MATLAB where you can find demo examples of different types of code by merely writing a single word, and you will be directed to the official page of MATLAB where all the demos of various programs are present. 

  1. whatsnew

If you want to get the Readme files of MATLAB, you just have to write this command in the command prompt and you will get the required output.

  1. why

This command has some different types of work. Every time you write “Why” in your command prompt, you will get a different type of sentence with a different meaning.

  1. home

This is a command resembling the “clc” command where you can go to the start of the command prompt and all the results and writings will be cleared from the screen and you will start writing from the beginning.

  1. global

This command is used to declare the variable globally. In other words, you will not have to declare the variable again and again in different sections, but it will be defined once and can be used anywhere in the program.

Commands Related to variables in and Workspace Information

Here is another category that deals with variable or workspace information, and you can easily perform them as you have practised the commands discussed above. So here is the list of this particular type. 

  1. who

This command is used to get all the variables that are declared in the workspace in which you are working.

Command Window in MATLAB, basic commands in matlab, matlab command window, matlab basic commands

  1. whos

If you want to know the variables declared in the workspace along with their sizes, then you will use this command. In this way, by adding only one character, you can also examine the size of the variable.

  1. clc

Sometimes, or I should say, many times, we want to clear the screen so we may try other codes and commands. For this, you do not have to select all the content and then press backspace, but you just have to write a simple “clc” command and all the data will vanish from your screen. But be careful while using this command because once the data is removed, you will never get the same data back.

  1. clear x,y,z

Consider the case when you just want to remove the specific lines of code or the variables and other code that are useful to you. Then you will use the clear command in a specific manner in which you will specify the variables that you want to remove from the screen and the memory. In this way, the declaration and erasure of data become easy.

  1. mlock fun

As we said earlier, it may be a disaster in your code if you clear the instructions in the code that were supposed to be there in the command prompt, and in such cases, you can lock the function by putting the name of that particular function just at the place of “fun” in this command.

  1. clf

As we have defined the figure window in our previous lecture, if you have the results of your code in the form of a figure window and want to close it with the help of a simple command, then simply write this command and the window will be closed.

Commands Related to Files and Directory Information

While using MATLAB, I face some cases where I have to think a lot about the directory and want to get information about different files saved in MATLAB by e. So, I found some interesting commands that tell me the exact information about the directories and files I am using efficiently and in great detail. Some of them are given below:

  1. cd

It changes the current working directory. It seems the same command we use in the command prompt of windows.

Command Window in MATLAB, basic commands in matlab, matlab command window, matlab basic commands

  1. dir

The purpose of this command is to see the content of the current directory. 

  1. copyfile

This command is used to copy the content of the files that we are working on. 

  1. rmdir

To remove the current directory from your MATLAB, we use this simple command. 

  1. what

It is an interesting command. You can access all the data on which you are working with the help of this simple one-word command.

Command Window in MATLAB, basic commands in matlab, matlab command window, matlab basic commands

General Information with The Help of Command

Yes, it is right. You can find general information about your computer with the help of commands in the command prompt. MATLAB does not only work as simple software that works separately from the other functions of the computer but it is also connected to the internal system of your PC. For instance, if you want to know the basic information about your PC, then you have to see the commands given below:

  1. clock

This is my favourite command. You can have the time and date in the form of a vector wall clock by writing this on your command prompt.

Command Window in MATLAB, basic commands in matlab, matlab command window, matlab basic commands

  1. ver

The licence and version of MATLAB can be seen with the help of this command.

  1. bench

This command must be used when you want to compare your computer to other devices while MATLAB is running. 

  1. computer

Many times, people do not know the type and specifications of the computer, and they can find them with the help of this command.

Command Window in MATLAB, basic commands in matlab, matlab command window, matlab basic commands

Keep in mind, just like some other programming languages, MATLAB is a case-sensitive language, and therefore, if you put these commands with different spellings or change the way of the writing that they were supposed to be, you will get an error. Usually, if the case or one or two characters are changed, MATLAB gives you the suggestions and, therefore, you can easily press the enter key and get the required work from MATLAB. Otherwise, you have to write the exact command.

Examples of Numerical Problems in MATLAB Command Prompt

Now, you know the basics and easy commands that are used in the command prompt, you can easily use the command prompt for different numerical problems. Now, we are starting MATLAB and solving the simplest numerical problems, and then we will move towards more complex problems. 

First of all, have a look at the equation that we are going to solve in MATLAB.

4x + 2 = 18

Here, x is the variable, and we want to find the value of this variable. So, we are using the following code to get the required output. You must know that the 18 on the right-hand side is moved to the left-hand side and, therefore, the equation becomes

4x + 2 - 18= 0

4x -18 = 0

We will write this problem in MATLAB and will get the results:

Command Window in MATLAB, basic commands in matlab, matlab command window, matlab basic commands

As you can understand with the help of this image, we are declaring a variable with the name “equation” and then feeding the values of x and the constant into it. By default, MATLAB reads the equation from the right side, and it reads the rightmost value as constant, and after that, moving towards the left increases the value of the polynomial. So, MATLAB understood that 4 is the value of variable x. 

Consider another equation that is shown as:

34x4 +45 -12=0

Here, you can see that the cubic value of the variable x is missing, so in place of this value, we will write zero. So the code and the output of the equation given above are:

Command Window in MATLAB, basic commands in matlab, matlab command window, matlab basic commands

You can use any word instead of "equation" to declare the equation. Yet, be careful, you have to write the exact word in the root command to get the desired results. The roots command simply takes the equation, solves it, and provides us with the result instantly.

So, it was the day when we learned a lot about the command prompt and saw some amazing commands related to MATLAB that, when written on the command prompt, give us the useful required information, and we checked most of them during the lecture. Your homework is to check the missing commands and get the results related to MATLAB. We will do some complex calculations in the next session, and now you are ready to get the answers to the complex calculations and codes, so stay with us for more action.