Introduction to MATLAB environment 2

Why Familiarity with Environment 2? In preparing this training course, we have studied, reviewed, and consulted a lot! As we said in the first meetings, we decided not to bombard the interested parties with MATLAB facilities and orders! Prepare the material so that the depth of training gradually increases. In the MATLAB 1 introduction session, you did not need to get acquainted with MATLAB help or MATLAB mfile. But after ten MATLAB training sessions, you should learn these today because we will need them in the sessions. We will be familiar with MATLAB environment again!

Importance of help MATLAB

MATLAB has extensive help or help system built into it. It is no exaggeration to say that the MATLAB guide is very powerful and comprehensive. This guide contains a complete and detailed description of the many MATLAB commands and functions. This guide system is very useful for people who are beginners in MATLAB. But even MATLAB experts still use the MATLAB helper system to review the details of MATLAB commands and functions.

But what good is a MATLAB guide? Suppose you have a new command that you do not know how to use. The MATLAB guide gives you all the information about that command along with several examples. All MATLAB commands have a description page. Descriptions that can help you with coding problems in MATLAB. You do not need the internet to use MATLAB guide! Because, as mentioned before, this guide is built into MATLAB. This is a wonderful feature. Because you will have access to the most complete information possible about the command you want as quickly as possible. The MATLAB guide environment is a template for many Python frameworks such as Nampy, Matplotlib, etc., and they have created online guides with the same structure for their frameworks. Most programming languages ​​have an online guide. But in addition to the online guide, MATLAB also has an offline guide that you will be familiar with in this session.

Well, let’s talk about how to use MATLAB help in a meeting with MATLAB 2

How to use MATLAB help

There are several ways to search for a command in the MATLAB guide. These methods are a little different, but they all have their own effectiveness. Here are some ways to access the information in command in the MATLAB guide.

The first method is to enter the name of the command or function we want in the Search Documentation field and then press Enter. There is a Search Documentation section in the right corner of MATLAB, which is shown in red in the figure below.

help matlab

To make our explanation more concrete, we will proceed with an example. We have learned about several functions in previous sessions. For example, in the previous session, we checked the size command in MATLAB. Let’s look at MATLAB’s description of size. To do this, enter the phrase size in the specified field. You will notice that immediately after writing the phrase size, MATLAB offers us suggestions:

The title of the commands suggested by MATLAB is highlighted in blue. Below each title is a brief description of the command. You can see that in the first line, under the title Array size. We also wanted to use size to find the size of arrays. Click on the first line to go to the size description page:


help window

You can see that in the first line, the performance of the command is summarized as briefly as possible. By looking at the phrase Array size, you will notice that this command gives the size of an array. In the Syntax section, all the cases that we can input and output with the size command are listed. The next section is the Description. This section explains the commands in the Syntax section. To the right of each section of the Description, there is a blue phrase with the title example. Clicking on this phrase will take you to an example that belongs to the same section. After the Description section, various examples are given.

Sometimes we do not have the patience to read Syntax. We immediately go to the examples… with these examples, we easily understand how to use the command we want. Of course, you must have a MATLAB background to understand, for example, how to use the command…

Let’s go back a bit… Now, what if we press the Enter key after typing the phrase size in Search Documentation? Let’s try. This will open a new window:


You can see that the first line says size- Array size. That’s what we want, just click on it to enter the description page. It looks like a Google search box and no special explanation is needed…

Let’s go to the second method, how to use MATLAB help in the introduction session with MATLAB 2.

The second way to use the MATLAB guide is to use the F1 key. This method will not open a new window. All you have to do is type the command you want in the Command Window. After typing the command (do not press Enter), press the F1 key. This will open a box:


help F1 MATLAB

If you scroll through the opened box, you will see that the information we saw in the first method is given here in full. We can read this information and then hit the cross key and close the box.

The third method is to write the phrase help and enter the command we want in front of it. For example, here we want to see information about size. It is enough to write:


cmd help MATLAB

You will see that in this case the description is displayed in the Command Window. The explanation given is more concise than the previous two methods. If you are careful, only the description of the Description section is given. In addition, an example is given.

We reviewed the information in the MATLAB guide in three ways. The description structure is the same for all MATLAB commands and functions. That is, they all have a summary, a syntax, a description, and an examples. Using MATLAB help is very, very useful. So make sure you get used to looking for a command or function in a MATLAB guide before asking your friends or teacher about it.

Introduction to MATLAB 2 environment is not difficult. We just went halfway through the meeting. Let’s go to the last part…

m-file in MATLAB

Familiarity with the MATLAB 1 environment, we became familiar with the Command Window, Command History, Current Folder, and Workspace windows. In this section, we want to introduce a new window. MATLAB has another window called M-File or Script. Normally this window does not exist when we open MATLAB.

But what is the philosophy of M-File? Suppose you are working on a big project. A project that has, for example, 200 lines of code! You want to do this project in four days. That means typing 50 lines of code every day. Suppose you wrote 50 lines yesterday and you want to continue today. To do this, go to the Command History window and run each command again in the Command Window! But that doesn’t sound very wise, does it? Can we call 50 command lines again? On the last day, we have to call 150 command lines. We need something like Word software to store these 50 lines and access them the next day. It is true? MATLAB also has a solution to this problem. The solution to this problem is M-File. To open an M-File, click New Script on the Home tab:


After clicking on New Script, a new window will open:


You will see a new window open at the top of the Command Window. What other changes have been made? Pay attention to the MATLAB tabs. The Home tab was already active. But after opening the M-File, the Editor tab is active. There are settings for M-File in this tab.

The trick is to increase the number of windows in Figure . If your screen is small, each of these windows will be displayed small. And well, that makes it difficult to code. Many professional coders have large screens or two screens. So there is no way for a small screen? Why, pay attention to the picture below. The option around which the circle is drawn is related to the settings of each window. You have four options for changing the display of windows, which are:

  • Minimize: This shrinks the window to get an image like Figure 9. In this case, there is an Auto-hide window. That means it opens every time you click on it. Then it automatically shrinks again. The Current Folder window is usually left in this state. Now the size of the windows gets a little bigger.
  • Maximize: Well, it covers the whole MATLAB window.
  • Undock: The window is separated from the MATLAB environment. Independent itself becomes a separate window.
  • Close: The window closes completely.

You can also move the size of the windows with the border line between the two windows. In general, the necessary facilities are provided for you to arrange the windows in different sizes as you are comfortable and delete, minimize and any you want.