matlab matlab matlab (an abbreviation of "matrix laboratory") is a proprietary multi-paradigm programming language and numeric computing environment 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. matlab (programming language)paradigmmulti-paradigm: functional, imperative, procedural, object-oriented, arraydesigned bycleve molerdevelopermathworksfirst appearedlate 1970sstable releaser2023a / february 22, 2023 (february 22, 2023) typing disciplinedynamic, weakfilename extensions.m, .p, .mex*, .mat, .fig, .mlx, .mlapp, .mltbx, .mlappinstall, .mlpkginstallwebsitemathworks.cominfluenced by apl eispack linpack pl/0 speakeasy influenced julia octave scilab intlab matlab programming at wikibooks matlab (software)l-shaped membrane logodeveloper(s)mathworksinitial release1984 (1984)stable releaser2023a / february 22, 2023 (february 22, 2023) written inc/c++, matlaboperating systemwindows, macos, and linuxplatformia-32, x86-64typenumerical computinglicenseproprietary commercial softwarewebsitemathworks.com although matlab is intended primarily for numeric 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. as of 2020, matlab has more than 4 million users worldwide. they come from various backgrounds of engineering, science, and economics. of note, as of 2017, more than 5000 global colleges and universities use matlab to support instruction and research. history origins matlab was invented by mathematician and computer programmer cleve moler. the idea for matlab was based on his 1960s phd thesis. moler became a math professor at the university of new mexico and started developing matlab for his students as a hobby. he developed matlab's initial linear algebra programming in 1967 with his one-time thesis advisor, george forsythe. this was followed by fortran code for linear equations in 1971. in the beginning (before version 1.0) matlab "was not a programming language; it was a simple interactive matrix calculator. there were no programs, no toolboxes, no graphics. and no odes or ffts." the first early version of matlab was completed in the late 1970s. the software was disclosed to the public for the first time in february 1979 at the naval postgraduate school in california. early versions of matlab were simple matrix calculators with 71 pre-built functions. at the time, matlab was distributed for free to universities. moler would leave copies at universities he visited and the software developed a strong following in the math departments of university campuses.: 5 in the 1980s, cleve moler met john n. little. they decided to reprogram matlab in c and market it for the ibm desktops that were replacing mainframe computers at the time. john little and programmer steve bangert re-programmed matlab in c, created the matlab programming language, and developed features for toolboxes. commercial development matlab was first released as a commercial product in 1984 at the automatic control conference in las vegas. mathworks, inc. was founded to develop the software and the matlab programming language was released. the first matlab sale was the following year, when nick trefethen from the massachusetts institute of technology bought ten copies. by the end of the 1980s, several hundred copies of matlab had been sold to universities for student use. the software was popularized largely thanks to toolboxes created by experts in various fields for performing specialized mathematical tasks. many of the toolboxes were developed as a result of stanford students that used matlab in academia, then brought the software with them to the private sector. over time, matlab was re-written for early operating systems created by digital equipment corporation, vax, sun microsystems, and for unix pcs. version 3 was released in 1987. the first matlab compiler was developed by stephen c. johnson in the 1990s. in 2000, mathworks added a fortran-based library for linear algebra in matlab 6, replacing the software's original linpack and eispack subroutines that were in c. matlab's parallel computing toolbox was released at the 2004 supercomputing conference and support for graphics processing units (gpus) was added to it in 2010. recent history some especially large changes to the software were made with version 8 in 2012. the user interface was reworked and simulink's functionality was expanded. by 2016, matlab had introduced several technical and user interface improvements, including the matlab live editor notebook, and other features. syntax the matlab application is built around the matlab programming language. common usage of the matlab application involves using the "command window" as an interactive mathematical shell or executing text files containing matlab code. variables variables are defined using the assignment operator, =. matlab is a weakly typed programming language because types are implicitly converted. it is an inferred typed language because variables can be assigned without declaring their type, except if they are to be treated as symbolic objects, and that their type can change. values can come from constants, from computation involving values of other variables, or from the output of a function. for example: >> x = 17 x = 17 >> x = 'hat' x = hat >> x = x = 12.0000 1.5708 >> y = 3*sin(x) y = -1.6097 3.0000 vectors and matrices a simple array is defined using the colon syntax: initial:increment:terminator. for instance: >> array = 1:2:9 array = 1 3 5 7 9 defines a variable named array (or assigns a new value to an existing variable with the name array) which is an array consisting of the values 1, 3, 5, 7, and 9. that is, the array starts at 1 (the initial value), increments with each step from the previous value by 2 (the increment value), and stops once it reaches (or is about to exceed) 9 (the terminator value). the increment value can actually be left out of this syntax (along with one of the colons), to use a default value of 1. >> ari = 1:5 ari = 1 2 3 4 5 assigns to the variable named ari an array with the values 1, 2, 3, 4, and 5, since the default value of 1 is used as the increment. indexing is one-based, which is the usual convention for matrices in mathematics, unlike zero-based indexing commonly used in other programming languages such as c, c++, and java. matrices can be defined by separating the elements of a row with blank space or comma and using a semicolon to separate the rows. the list of elements should be surrounded by square brackets . parentheses () are used to access elements and subarrays (they are also used to denote a function argument list). >> a = a = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1 >> a(2,3) ans = 11 sets of indices can be specified by expressions such as 2:4, which evaluates to . for example, a submatrix taken from rows 2 through 4 and columns 3 through 4 can be written as: >> a(2:4,3:4) ans = 11 8 7 12 14 1 a square identity matrix of size n can be generated using the function eye, and matrices of any size with zeros or ones can be generated with the functions zeros and ones, respectively. >> eye(3,3) ans = 1 0 0 0 1 0 0 0 1 >> zeros(2,3) ans = 0 0 0 0 0 0 >> ones(2,3) ans = 1 1 1 1 1 1 transposing a vector or a matrix is done either by the function transpose or by adding dot-prime after the matrix (without the dot, prime will perform conjugate transpose for complex arrays): >> a = , b = a.', c = transpose(a) a = 1 2 b = 1 2 c = 1 2 >> d = , d.' d = 0 3 1 5 ans = 0 1 3 5 most functions accept arrays as input and operate element-wise on each element. for example, mod(2*j,n) will multiply every element in j by 2, and then reduce each element modulo n. matlab does include standard for and while loops, but (as in other similar applications such as r), using the vectorized notation is encouraged and is often faster to execute. the following code, excerpted from the function magic.m, creates a magic square m for odd values of n (matlab function meshgrid is used here to generate square matrices i and j containing 1:n): = meshgrid(1:n); a = mod(i + j - (n + 3) / 2, n); b = mod(i + 2 * j - 2, n); m = n * a + b + 1; structures matlab supports structure data types. since all variables in matlab are arrays, a more adequate name is "structure array", where each element of the array has the same field names. in addition, matlab supports dynamic field names (field look-ups by name, field manipulations, etc.). functions when creating a matlab function, the name of the file should match the name of the first function in the file. valid function names begin with an alphabetic character, and can contain letters, numbers, or underscores. variables and functions are case sensitive. rgbimage = imread('ecg.png'); grayimage = rgb2gray(rgbimage); % for non-indexed images level = graythresh(grayimage); % threshold for converting image to binary, binaryimage = im2bw(grayimage, level); % extract the individual red, green, and blue color channels. redchannel = rgbimage(:, :, 1); greenchannel = rgbimage(:, :, 2); bluechannel = rgbimage(:, :, 3); % make the black parts pure red. redchannel(~binaryimage) = 255; greenchannel(~binaryimage) = 0; bluechannel(~binaryimage) = 0; % now recombine to form the output image. rgbimageout = cat(3, redchannel, greenchannel, bluechannel); imshow(rgbimageout); function handles matlab supports elements of lambda calculus by introducing function handles, or function references, which are implemented either in .m files or anonymous/nested functions. classes and object-oriented programming matlab supports object-oriented programming including classes, inheritance, virtual dispatch, packages, pass-by-value semantics, and pass-by-reference semantics. however, the syntax and calling conventions are significantly different from other languages. matlab has value classes and reference classes, depending on whether the class has handle as a super-class (for reference classes) or not (for value classes). method call behavior is different between value and reference classes. for example, a call to a method: object.method(); can alter any member of object only if object is an instance of a reference class, otherwise value class methods must return a new instance if it needs to modify the object. an example of a simple class is provided below: classdef hello methods function greet(obj) disp('hello!') end end end when put into a file named hello.m, this can be executed with the following commands: >> x = hello(); >> x.greet(); hello! graphics and graphical user interface programming matlab has tightly integrated graph-plotting features. for example, the function plot can be used to produce a graph from two vectors x and y. the code: x = 0:pi/100:2*pi; y = sin(x); plot(x,y) produces the following figure of the sine function: matlab supports three-dimensional graphics as well: = meshgrid(-10:0.25:10,-10:0.25:10); f = sinc(sqrt((x/pi).^2+(y/pi).^2)); mesh(x,y,f); axis() xlabel('') ylabel('') zlabel(' ()') hidden off = meshgrid(-10:0.25:10,-10:0.25:10); f = sinc(sqrt((x/pi).^2+(y/pi).^2)); surf(x,y,f); axis() xlabel('') ylabel('') zlabel(' ()') this code produces a wireframe 3d plot of the two-dimensional unnormalized sinc function: this code produces a surface 3d plot of the two-dimensional unnormalized sinc function: matlab supports developing graphical user interface (gui) applications. uis can be generated either programmatically or using visual design environments such as guide and app designer. matlab and other languages matlab can call functions and subroutines written in the programming languages c or fortran. a wrapper function is created allowing matlab data types to be passed and returned. mex files (matlab executables) are the dynamically loadable object files created by compiling such functions. since 2014 increasing two-way interfacing with python was being added. libraries written in perl, java, activex or .net can be directly called from matlab, and many matlab libraries (for example xml or sql support) are implemented as wrappers around java or activex libraries. calling matlab from java is more complicated, but can be done with a matlab toolbox which is sold separately by mathworks, or using an undocumented mechanism called jmi (java-to-matlab interface), (which should not be confused with the unrelated java metadata interface that is also called jmi). official matlab api for java was added in 2016. as alternatives to the mupad based symbolic math toolbox available from mathworks, matlab can be connected to maple or mathematica. libraries also exist to import and export mathml. relations to us sanctions in 2020, matlab withdrew services from two chinese universities as a result of us sanctions.