Menu Close

Getting Started With MATLAB 

Posted in MatLab

MATLAB (MATrix LABoratory) is a programming and numerical computation platform used for tasks such as; data analysis, signal and image processing, <<yadayadayada look thru lecs>> and many more. It is one of the most important programs that engineers, <<software, etc>> will need to master to greatly increase the efficiency of their work in the field. 

In this set of MATLAB articles, you will be guided through everything, from the basics of the MATLAB interface to <<hard things you can do with matlab>>. Let’s start. 

Writing scripts in MATLAB is practically analogous to writing code in any other language. However, MATLAB has an incredibly large and comprehensive library of functions. We will go over many in these articles, but keep in mind that for nearly any computation you wish to make, MATLAB most likely already has a function to compute it in one step, saving you the time of having to write out the formula like you would have to in other languages. <<maybe give some examples, like nchoosek()>> 

The MATLAB Interface:

Basic Commands:  

clc; – clears all text from the Command Window. 

clear all; – clears the workspace, meaning it will reset (clear) variables, cached memory, etc. 

close all; – closes all open figures. Later, we will see how it will clean up and prevent new plots from appearing on old graphs. 

clr; – runs clc, clear all, close all, all at once. 

Note that it is best to run these commands for regular scripts, which will save keystrokes, time, and reduce clutter. However, running these within function scripts can prove to erase important information, especially when running functions as part of a larger script. In short, it is highly recommended to not run these commands in your functions, but only at the start of other scripts. 

% – for leaving comments. Similar to // in C++ or a # in Python. 

%% – for leaving bolded comment headers. Leaving a %% will visibly separate sections of your script, like so: (img) 

% { %} – for leaving block comments. Similar to /* … */ in C++. 

disp() – for displaying data in the command window. Much like a print function. 

Calculator Replacement

We can see how MATLAB can replace the need for a calculator when working. In fact, many engineers will have an instance of MATLAB open in place of using a calculator. Let us explore some of the basic calculator functions that are made possible for us with this program: 

Basic Arithmetic operators: 

  • – the addition operator. 
  • – the subtraction operator. 

* – the multiplication operator. 

/ – the division operator. 

^ – the power operator. 

sqrt() – the square root operator. 

Firstly, it should be noted that MATLAB uses these operators for simple scalar operations, however, these operators will later be re-used and modified when we move onto more complex matrix and array operations. 

For now, we can combine these to perform basic arithmetic sequences; (img) 

Of course, MATLAB follows BEDMAS operators. 

Next, we shall explore variable assignment.

Leave a Reply

Your email address will not be published. Required fields are marked *