MATLAB Programming/Fundamentals of MATLAB

Main screen of MATLAB

edit

When the MATLAB is opened for the first time after installing, you will see the MATLAB main display shown as followed (Note that the version is R2020a, which other versions may look more or less similar):

 
























The main screen of MATLAB will consists of the following (in order from top to bottom):

  • Search Bar - Can search the documentations online for any commands / functions / class
  • Menu Bar - The shortcut keys on top of the window to access commonly used features such as creating new script, running scripts or launching SIMULINK
  • Home Tab - Commonly used features/functions are grouped here
  • Plots Tab - The plot charts is shown here. Basic charts (without additional toolbox are shown as follows):
Line Plots, Bar Plots, Scatter Plots, Pie Chart, Histogram, Polar Plots, Geographic Plots, Contour Plots,3D Surface, Vector Field and Analytic Plots
  • Apps Tab - The additional installed toolbox with related functionality are shown here
  • Current Folder Panel — The created files are accessed at this panel
  • Command Window Panel — All of the workings are done at this panel, enter commands at the command line, indicated by the prompt (>>).
  • Workspace Panel — Explore data that you had created or import the data from files at this panel

Hello World

edit

All programming languages are introduced by the most famous computer program on the planet, "Hello, world!", so let's begin with that.

In the center, you can see a window labelled as "Command Window". The cursor should be already flickering there; all you now have to do is to write as followed:

disp('Hello, world!');

and press the return key. The output will be shown just below the command as

Hello, world!


Note: To pass the argument string in single quotes (not double), but why so? Because we might need to use double quotes inside the string and that would be interpreted as the end of the string argument. Having said this, it is assured that double quotes work inside the string, however escape sequences may have to be used to get the string right.

Start afresh

edit

In MATLAB , once you are started working with a lot of mathematical formulas for one project , you will need to start afresh for your new project.

To do this, just type as follows:

clear
clc
close all

What does this three lines do ?

clear - This command will removes all stored variables from the workspace.

clc - This command will clear the command window and homes the cursor.

close all - This command will closes all the open figure windows.

References

edit

[1]

  1. https://web.archive.org/web/20210615132903/https://www.educba.com/matlab-free/?source=leftnav