MATLAB Fundamentals
MATLAB is a programming language and computing environment built around matrices and arrays, used by engineers and scientists to analyze data, develop algorithms, and visualize results. You write commands that operate on whole arrays of numbers, not just one value at a time.
itProgramming languages | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic: MATLAB Fundamentals
MATLAB is a programming and numeric computing environment built around arrays, which is a reassuringly compact idea until the arrays begin having opinions about their shape. It exists so engineers and scientists can move from a calculation to a plotted result without first constructing a small private nation of Fortran programs. The command line, editor, workspace, and plot tools are all there to keep that work in one place.
The important word is array: every value has a shape. A scalar is a one-by-one array. A vector is one row or one column. A matrix has both. MATLAB is unusually happy to perform a calculation across a whole array, which is productive right up to the moment a row vector meets a column vector and produces a result that is mathematically valid but not the result on your shopping list.
That is why the period deserves its own tiny warning label. A * B follows matrix multiplication rules. A .* B multiplies matching elements. The symbols have the same family resemblance and entirely different jobs, like two buttons in a lift marked "open" and "deploy". Before running an expression, picture the result's shape. Then use size to see whether reality has accepted the proposal.
Start at the command line when a calculation is still a question. Once it works, put the sequence in a script so it can be run again. When the calculation needs a proper boundary, make it a function with declared inputs and outputs. A script shares the workspace; a function tells everyone which values cross the door. This distinction becomes valuable at exactly the moment the workspace begins to resemble a drawer full of cables.
Plots are not decoration. plot(x,y) connects matched values, and labels let somebody outside the current session understand what the axes mean. Use a plot to inspect a result before trusting it. A result can run while its shapes, types, or units are still wrong, which is MATLAB's polite way of saying that it did precisely what it was told.
Next, open the Intro for the map of MATLAB, Simulink, and toolboxes. The Slides make the array and operator decisions visible at a glance. The Cheatsheet is for syntax while working. Then use the practice reference and exercise to turn one sampled signal into a function and a labeled plot. After that, choose a toolbox because the problem needs it, not because the toolbox shelf looks inviting.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://www.mathworks.com/products/matlab.html
Supports
- MATLAB is a programming and numeric computation environment for algorithm development, data analysis, and visualization, described by MathWorks as the language of engineers and scientists.
- MATLAB includes interactive apps, a high-level language, and professionally developed, tested, and documented toolboxes for specialized workflows.
- Simulink provides model-based design with a graphical block-diagram approach and automatic code generation for embedded targets.
- MATLAB interoperates with Python, Visual Studio, and GitHub.
- MATLAB requires a license; free trial versions are available alongside personal, commercial, academic, and teaching license types.
- https://www.mathworks.com/help/matlab/getting-started-with-matlab.html
Supports
- MATLAB operates around matrices and arrays as its primary data structure.
- The MATLAB desktop includes the command line, Command History, Workspace panel, and Variables editor.
- The workspace stores variables created in MATLAB or imported from external sources.
- MATLAB provides 2-D and 3-D plotting for data visualization.
- https://www.mathworks.com/help/matlab/matrices-and-arrays.html
Supports
- Matrices and arrays are the fundamental representation of information and data in MATLAB.
- MATLAB provides zeros, ones, rand, eye, and diag for creating arrays with specific properties.
- The colon operator and the end keyword are used for subscripting and referencing the last index.
- MATLAB supports array operations including concatenation, reshaping, and transposing.
- https://www.mathworks.com/help/matlab/learn_matlab/array-indexing.html
Supports
- MATLAB uses one-based array indexing with row and column subscripts, A(row,column).
- A single subscript performs linear indexing, traversing down each column in order.
- The colon operator specifies a range, all elements in a dimension, or equally spaced values.
- Assigning to an index beyond current array bounds expands the array; reading beyond bounds is an error.
- https://www.mathworks.com/help/matlab/matlab_prog/array-vs-matrix-operations.html
Supports
- The period character distinguishes array (element-wise) operations from matrix operations.
- Element-wise operators are .*, ./, .\, and .^; matrix operators are *, /, \, and ^.
- Matrix multiplication requires the first operand's column count to equal the second operand's row count.
- Addition and subtraction use the same symbols for both array and matrix operations.
- Transpose without conjugation is .'; complex conjugate transpose is '.
- https://www.mathworks.com/help/matlab/data-types.html
Supports
- MATLAB stores numeric variables as double-precision floating point by default, alongside integer and single-precision types.
- MATLAB provides character arrays and string arrays for text.
- Cell arrays can contain data of varying types and sizes.
- Structures hold named fields of varying types and sizes.
- Tables hold tabular data whose named columns can have different types.
- https://www.mathworks.com/help/matlab/scripts.html
Supports
- Scripts are the simplest type of program file and have no input or output arguments.
- Functions accept input arguments and return output arguments.
- Local functions can be defined inside a script file alongside script code.
- Live scripts, created in the Live Editor, combine code with formatted text, equations, and visualizations in one document.
- Scripts, functions, and live scripts are stored as MATLAB code files.
- https://www.mathworks.com/help/matlab/matlab_prog/create-scripts.html
Supports
- A script contains sequential commands with no input or output arguments.
- When a script finishes running, its variables remain in the MATLAB workspace.
- Scripts share the base workspace with the interactive session and with other scripts.
- https://www.mathworks.com/help/matlab/function-basics.html
Supports
- A MATLAB function begins with a function declaration line naming the function, its inputs, and its outputs.
- Functions are stored in program files containing sequential commands ending with an end statement.
- MATLAB also supports anonymous functions as a compact alternative for simple operations.
- https://www.mathworks.com/help/matlab/ref/plot.html
Supports
- plot(x,y) creates a 2-D line plot connecting data points from matched x and y vectors.
- If the input to plot is a matrix, the plot contains one line for each column.
- title, xlabel, and ylabel add descriptive text to a plot.
- https://www.mathworks.com/products.html
Supports
- MathWorks organizes MATLAB add-ons into toolboxes covering domains such as signal processing and communications, automotive, aerospace, robotics, finance, and image processing.
- Simulink provides simulation and modeling capabilities including physical modeling components and systems engineering tools.
- MATLAB Online and Simulink Online provide browser-based access alongside student and campus licensing.
- https://matlabacademy.mathworks.com/details/matlab-onramp/gettingstarted
Supports
- MATLAB Onramp is a free, two-hour, self-paced interactive course covering commands, variables, indexing, plotting, and importing external data.
- MATLAB Onramp is accessed through a web browser and requires no separate MATLAB license.
- https://github.com/mathworks/awesome-matlab-students
Supports
- This repository is maintained by MathWorks as a resource hub for students learning MATLAB and Simulink.
- It links free onramp courses, cheat sheets, practice challenges, hardware integration guides, and student community programs.
- https://github.com/uhub/awesome-matlab
Supports
- This curated list catalogs MATLAB frameworks, libraries, and software, including YALMIP, CVX, the Robotics Toolbox for MATLAB, export_fig, and matlab2tikz.
- https://yalmip.github.io/
Supports
- YALMIP is a MATLAB and Octave toolbox for optimization modeling, letting users formulate linear, quadratic, semidefinite, and nonconvex problems and interfacing with external solvers.
- https://cvxr.com/cvx/
Supports
- CVX turns MATLAB into a modeling language for specifying convex optimization problems, including disciplined convex programming and geometric programming, using standard MATLAB expression syntax.
- https://petercorke.com/toolboxes/robotics-toolbox/
Supports
- The Robotics Toolbox for MATLAB provides functions and classes for robot kinematics, dynamics, and trajectory generation, covering serial-link manipulators and mobile robots including path planning and localization.
- https://github.com/altmany/export_fig
Supports
- export_fig is a MATLAB toolbox for exporting publication-quality figures with better on-screen fidelity than MATLAB's built-in export functions.
- https://github.com/matlab2tikz/matlab2tikz
Supports
- matlab2tikz converts native MATLAB figures into TikZ and Pgfplots code that integrates directly with LaTeX documents.
- https://www.mathworks.com/company/newsletters/articles/a-brief-history-of-matlab.html
Supports
- MATLAB began as an interactive matrix calculator based on LINPACK and EISPACK and evolved through commercial releases, toolboxes, sparse matrices, the desktop, GPU support, the Live Editor, and newer array types.
- PC-MATLAB debuted in 1984, Pro-MATLAB followed in 1985, and the MATLAB desktop was introduced in 2000.
- MATLAB 5 introduced cell arrays and structures in 1996; the Live Editor was introduced in 2016.
- https://blogs.mathworks.com/cleve/2012/08/27/matlab-debut-and-the-potted-palm/
Supports
- The first public appearance of PC-MATLAB was at the IEEE Conference on Decision and Control in December 1984.
- https://blogs.mathworks.com/loren/2016/10/24/matlab-arithmetic-expands-in-r2016b/
Supports
- R2016b introduced implicit expansion for supported element-wise operators and functions when dimensions are compatible.
- Implicit expansion can turn a row-vector and column-vector operation into an outer array instead of a dimension mismatch.
- https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html
Supports
- Incrementally growing arrays can adversely affect performance and memory use because resizing may require finding a larger contiguous block and moving the array.
- Preallocating a known maximum array size avoids repeated reallocation during loop-based construction.
- https://blogs.mathworks.com/loren/2012/11/29/understanding-array-preallocation/
Supports
- Unnecessary preallocation followed by replacement with a returned array adds allocation without avoiding the growth it is intended to prevent.
- https://www.mathworks.com/help/parallel-computing/quick-start-parallel-computing-in-matlab.html
Supports
- MathWorks recommends vectorization and preallocation to improve sequential MATLAB performance before parallelizing code.
- https://octave.org/
Supports
- GNU Octave is an open-source numerical-computation environment whose syntax is largely compatible with MATLAB.
- https://wolfram.com/mathematica/
Supports
- Mathematica is a technical-computing environment with notebook documents and integrated symbolic and numeric computation.
- https://www.maplesoft.com/products/maple/
Supports
- Maple is commercial mathematics software for analysis, exploration, visualization, and solving mathematical problems.
- https://www.scilab.org/about/scilab-open-source-software
Supports
- Scilab is free and open-source engineering and scientific software released under GPL version 2.
