MATLAB (MATrix LABoratory) is a multi-paradigm numerical computing environment. It is a high-level programming language. A proprietary programming language developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, C#, Java, Fortran and Python.

Although MATLAB is intended primarily for numerical computing, an optional toolbox uses the MuPAD symbolic engine, allowing access to symbolic computing abilities. An additional package, Simulink, adds graphical multi-domain simulation and model-based design for dynamic and embedded systems

##### What is MATLAB?

MATLAB (Matrix Laboratory) is a high-performance programming language for technical computing. It is a fourth-generation programming language and numerical analysis environment. It integrates computation (IDE), visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include:

- Math and computation
- Algorithm development
- Data analysis, exploration, and visualization
- Modeling, simulation, and prototyping
- Scientific and engineering graphics
- Application development, including Graphical User Interface building
- It is used by engineers and scientists in many fields such as image and signal processing, control systems for industry, communications, smart grid design, robotics as well as computational finance.

##### Why MATLAB?

Matlab in not only a programming language, but a programming environment as well. It is very good at performing matrix operations, making it useful for things like image operations and control system analysis. It is very quick to develop code in Matlab. Many libraries (e.g. computer vision, signal analysis, GUI tools) are part of the Matlab ecosystem. This saves developers the time of installing and configuring new libraries to perform whatever tasks they have in mind. Instead, developers can quickly get an idea and try it out in code using the vast functionality of Matlab’s libraries.

One more thing that Matlab really excels at is its plotting functions. Matlab offers a variety of ways to visually display data. Furthermore, most of the plotting functions are very user-friendly and configuring the plots to look exactly as you would like is very easy to do.

##### What is GNU Octave?

GNU Octave is software featuring a high-level programming language, primarily intended for numerical computations. Octave helps in solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly compatible with Matlab. It may also be used as a batch-oriented language.

##### What is Xmath?

Xmath is an interactive scripting and graphics environment for Xwindow workstations.

With its significant improvement features on MATLAB¬type software, interactive mathematics,scripting functionalities are elaborated.

Following are the Xmath features:

- Sripting languages with OOP features.
- Libraries that are LNX and C language compatible.
- A debugging tools with GUI features.
- Color graphics can be pointed and clickable.
- A special layer is available that is programmable for MOTIF GUI.

##### What’s New in MATLAB R2017?

- New Desktop: Live Editor
- New Mathematics applications
- Language and Programming
- New Graphics functions
- Data Analysis
- Data stores
- Solve Data Import and Export Functions
- Application Builder
- Machine Learning & Deep Learning
- Advanced Software Development
- Database Toolbox Interface for MongoDB
- plitsqlquery Function
- Easy Verification and Validation
- Database Explorer App
- CUDA Code Generation from MATLAB
- Real software development
- MATLAB Interface to SQLite

##### Can you explain MEXfile in MATLAB?

The MEX file contains only one function or subroutine, and its name is the MEX file name. To call a MEX file, use the name of the file, without the file extension. The term mex stands for “MATLAB executable” and has different meanings, as shown in the following.

MEX Term

**source MEX file:** C, C++, or Fortran source code file.

**binary MEX file:** Dynamically linked subroutine executed in the MATLAB environment.

**MEX function library:** MATLAB C and Fortran API Reference library to perform operations in the MATLAB environment.

**mex build script:** MATLAB function to create a binary file from a source file.

##### What are the main system parts of MATLAB?

- MATLAB Language.
- MATLAB working environment.
- Graphics handler.
- MATLAB mathematical library.
- MATLAB Application Program Interface.

##### Can you explain MATLAB LANGUAGE?

MATLAB Language is a high¬level matrix/array language with control flow statements, functions, data structures,input/output, and object¬oriented programming features. It allows both “programming in the small” to rapidly create quick and dirty throw¬away programs, and “programming in the large” to create complete large and complex application programs.

##### Can you explain MATLAB Working Environment?

MATLAB supports export and import data across applications. Matlab Working Environment is the set of tools and facilities that you work with as the MATLAB user or programmer. It includes facilities for managing the variables in your workspace and importing and exporting data. It also includes tools for developing, managing, debugging, and profiling M¬files, MATLAB’s applications. Note that the Matlab environment is highly configurable, which means that it may not look exactly like this on your machine. (You can try selecting Desktop Desktop Layout -> Default from the menubar, but that may still not give you this exact configuration, depending on your particular version.)

##### Can you explain Simulink?

Simulink is a simulation and model-based design environment for dynamic and embedded systems, integrated with MATLAB. Simulink, also developed by MathWorks, is a data flow graphical programming language tool for modelling, simulating and analyzing multi-domain dynamic systems. Simulink is a graphical block diagramming tool with customizable set of block libraries

Simulink supports:

- System-level design
- Simulation
- Automatic code generation
- Testing and verification of embedded systems

##### Can you explain Graphics handler?

MATLAB provides a set of low-level functions that allows you to create and manipulate lines, surfaces, and other graphics objects. This system is called Handle Graphics. Most code written for numeric handles still works with object handles. For example, you can access graphics object properties and you can combine graphics objects into arrays, even if the objects belong to different classes

Graphics functions include 2-D and 3-D plotting functions to visualize data and communicate results. Customize plots either interactively or programmatically.

##### Can you explain MATLAB Application Program Interface (API)?

MATLAB API is a library that allows you to write C and FORTRAN programs that interact with MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and for reading and writing MAT-files.

##### Can you explain Script and Functions?

Script: The simplest type of MATLAB program is called a script. A script is a file with a .m extension that contains multiple sequential lines of MATLAB commands and function calls. You can run a script by typing its name at the command line. A script is simply a collection of Matlab commands in an m-file (a text file whose name ends in the extension “.m”). Upon typing the name of the file (without the extension), those commands are executed as if they had been entered at the keyboard

Functions: Functions operate on variables within their own workspace, which is also called the local workspace, separate from the workspace you access at the MATLAB command prompt which is called the base workspace. Functions can accept more than one input arguments and may return more than one output arguments.

Syntax: function [out1, out2… outN] = myfun(in1,in2,in3, …, inN)

##### Can you explain MATLAB Mathematical Function Library?

MATLAB Mathematical Function Library is a vast collection of computational algorithms ranging from elementary functions like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms.

##### Can you define Latex in MATLAB?

Matlab already handles naturally simple LaTeX encodings that allow introducing Greek lettters or modifying the font size and appearance in plots LaTeX form of symbolic expressioncollapse all in page. Syntax: latex(S) returns the LaTeX form of the symbolic expression S.

##### How the source code can be protected in Matlab?

By default, the code is saved in (.m) extension, which is secured but if the user wants it to be stored in a more secured way then he can try the following methods:

Make it as P-code: Convert some or all of your source code files to a content-obscured form called a P-code file (from its .p file extension), and distribute your application code in this format.

Compile into binary format: Compile your source code files using the MATLAB Compiler to produce a standalone application. Distribute the latter to end users of your application.

##### Can you define a P-code?

P-code files are purposely obscured; they offer a secure means of distribution outside of your organization. Pcode is a preparsed and encoded version of the M-file. It saves on the load time of the function. This is most likely not an issue except for very large M-files, since most are parsed only once anyway. Pcode also lets you hide the source code from others. There is no way to convert Pcode back to the M-file source. Pcode is platform independent.

##### Explain the functions used to read text files from a certain format in Matlab?

Following functions can be used to read a text file:

DLMREAD: It allows you to read files with fields delimited by any character.

TEXTREAD: It allows you to skip lines at the beginning, ignore certain comment lines, read text as well as numbers, and more.

myfile.txt: It is for the file which has nothing but numbers separated by space, and has a constant number of columns through the entire file. Other functions are FOPEN, FREAD, FSCANF, FGETL, FSEEK and FCLOSE.

##### Can you define Interpolation and extrapolation in Matlab?

Interpolation can be defined as taking out function values between different data points in an array whereas finding function values beyond the endpoints in an array is called extrapolation. Commonly both can be done by using nearby function values to define a polynomial approximation to the function that is good over a small region. There are two types of Interpolation and Extrapolation:

- Linear Interpolation and Extrapolation
- Quadratic Interpolation and Extrapolation

##### What is stress analysis in MATLAB?

MATLAB is used in aerospace engineering, space environment.

MATLAB is suitable for flexible dynamics.

These domain experts conduct stress analysis on various structures like metallic and composite structures.

To analyze the stress, NASTRAN, IDEAD, Oracle and PATRAN levels of proficiency is needed.

The tasks are also used on aircraft that is metallic structure.

The stress analysis includes control surface stiffness understanding, loop calculations, finite element modeling and fatigue testing requirement and analysis.

##### Can you explain fminsearch?

General fits which are fitted by giving a decent initial guess for fitting parameters in it is done by fminsearch which is a multidimensional minimizer routine.

Suppose we have a set of data points (xj , yj) and a proposed fitting function of the form y = f(x, a1, a2, a3, …).

For example: we could try to fit to an exponential function

With two adjustable parameters a1 and a2 as is done in the example in leastsq.m below:

f(x, a1, a2) = a1ea2x Or we could fit to a cubic polynomial in x2 with four adjustable parameters a1, a2, a3, a4 with this f:

f(x, a1, a2, a3, a4) = a1 + a2x2 + a3x4 + a4x6

##### Can you explain housekeeping functions in MATLAB?

Functions are those functions which do not really do math but are useful in programming.

Some functions are mentioned below:

clc : this is clears the command window; useful for beautifying printed output

ceil(x) : This is the nearest integer to x looking toward +1

close 3 : This is closes figure window 3

fliplr(A): This is flip a matrix A, left for right

fix(x) : This is the nearest integer to x looking toward zero

floor(x) : This is the nearest integer to x looking toward -1

length(a) : This is the number of elements in a vector

rem(x,y): This is the integer remainder of x/y; see online help if x or y are negative

mod(x,y): This is the integer remainder of x/y; see online help if x or y are negative

##### Do you know how to pre allocate a non-double matrix?

Preallocating a block of memory for holding a non double matrix is memory efficient.

It is faster to use the function ‘repmat’.

While allocating block of memory for a matrix, zeros are pre allocated to a matrix.

The function to pre allocate memory is int8().

Ex: matrix = int8(zeros(100));

Repmat function is used to create a single double matrix.

Ex: matrix2 = repmat(int8(0), 100, 100);

Thus, non-double matrix is pre allocated.

##### How Logarithmic plots can be plotted in Matlab?

Log and semi-log plots are plotted with the help of semilogx, semilogy, and loglog commands.

##### What are the common toolboxes present in Matlab?

Some of the common toolboxes in Matlab are

- Control System
- Fuzzy Logic
- Symbolic Math
- Image Processing
- LMI control
- Neural Networks
- Robust Control
- System Identification
- Signal Processing
- Statistics
- Wavelets
- System Identification

##### How to modify the MatLab Path?

To modify the MatLab Path use the PathTool GUI. Also, you can use add path directories from the command line and add the path to rc to write the current path back to ‘pathdef.m.’ In the case if you don’t have permission to write for ‘pathdef.m’ then pathrc can be written into a different file, you can execute from your ‘startup.m.’

##### How to call matlab in batch mode?

This can be done from the command line or from a makefile. You need a script (filename.m). Just type at the command line or include in the makefile: matlab<filename.m where filename.m can write to disk a figure, a binary, an ascii file, anything you want.

##### How polynomials can be represented in MatLab?

A polynomial in MatLab is denoted by a vector. To create a polynomial in MatLab enter each co-efficient of the polynomial into the vector in descending order

##### Can you explain pseudo random binary sequence and numeric precision in matlab?

Pseudo random binary sequence: A form of generating an M-file in the new Frequency Domain System Identification Toolbox, for a specified set of lengths (2^2-1 to 2^30-1) is called pseudo random binary sequence. It is also known as mlbs (for Maximum Length Binary Sequence).

Numeric precision: Numeric quantities which are represented as double precision floating point numbers is called numeric precision. On most computers, such numbers have 53 significant binary bits, which is about 15 or 16 decimal digits.

##### What is memory management functions in MATLAB?

Below is the list of memory management functions.

Clear: Removes variables from memory.

Save: Selectively persists variables to disk.

Pack: Saves the existing variables to disk, and then reloads them contiguously.

Load: Reloads a data file saved with the save function.

Quit: Exits MATLAB and returns all allocated memory to the system.

##### If one is appearing for Digital Signal Processing (DSP) position, he may often be asked what is the difference between rand and randn ?

The functions such as rand and randn used to model AWGN channel. The function ‘randn’ generates random numbers with normal distribution with mean value equal to zero and variance value of one. The function ‘rand’ generatea random numbers with uniform distribution. These are used in AWGN function of matlab.

##### What are the pros and cons of MATLAB?

**MATLAB Pros:**

- Its basic data element is the matrix. A simple integer is considered a matrix of one row and one column. Several mathematical operations that work on arrays or matrices are built-in to the Matlab environment. For example, cross-products, dot-products, determinants, inverse matrices.
- Vectorized operations. Adding two arrays together needs only one command, instead of a for or while loop.
- The graphical output is optimized for interaction. You can plot your data very easily, and then change colors, sizes, scales, etc., by using the graphical interactive tools.
- Matlab’s functionality can be greatly expanded by the addition of toolboxes. These are sets of specific functions that provided more specialized functionality. Ex: Excel link allows data to be written in a format recognized by Excel, Statistics Toolbox allows more specialized statistical manipulation of data (Anova, Basic Fits, etc.)

**MATLAB Cons:**

- It uses a large amount of memory and on slow computers it is very hard to use.
- It sits “on top” of Windows, getting as much CPU time as Windows allows it to have. This makes real-time applications very complicated.
- Matlab is a semi-interpreted language compared to a compiled language (like C/C++). An interpreted language runs directly from the program code and need to be converted to machine code at each line of your program. Whereas, compiled languages are compiled into machine code, which typically runs more quickly than interpreted languages.
- Matlab does not make for a great general-purpose language. Matlab does scientific computing very well, but many other languages can take on a variety of tasks including web development, back end, and rich GUIs.
- Using Matlab can use a larger amount of RAM than a compiled program. For most applications, a typical computer will be fine. However, processing larger images, videos, or data sets may eat up a larger amount of memory.

### Related posts:

- C Programming Interview Questions and Answers
- Dart Programming Interview Questions and Answers
- Delphi Programming Interview Questions and Answers
- Perl Interview Questions and Answers
- Python Interview Questions and Answers
- R Programming Interview Questions and Answers
- Ruby Programming Interview Questions and Answers
- Swift Programming Interview Questions and Answers