Questions tagged [matlab]

MATLAB is a high-level language and interactive programming environment for numerical computation and visualization developed by MathWorks. Don’t use both the [matlab] and [octave] tags, unless the question is explicitly about the similarities or differences between the two. When using this tag, please mention the MATLAB release you're working with (e.g. R2017a).

MATLAB (Matrix Laboratory) is a high-level language and interactive programming environment for numerical computation and visualization, developed by MathWorks. MATLAB can be used when performing tasks such as signal processing and communications, image and video processing, computational finance, and computational biology. It is the foundation for a number of other tools, including Simulink and various toolboxes that extend its core capabilities.

MATLAB is a cross-platform system developed since 1984. From the release of version 7.2 (R2006a) there has continued to be a biannual release cycle, with version "a" typically released in March/April and version "b" in September/October - based on the release history. For example R2017a and R2017b were the two releases in 2017.

MATLAB is a proprietary product of MathWorks. This means that, unlike open source languages, both programmers and users must own a valid software license in order to run MATLAB code.

There are several open source alternatives to MATLAB, in particular GNU Octave, which offers (mostly) bidirectional syntactic compatibility with MATLAB, Scilab, SciPy, and Julia.

Documentation

Informative links that show up quite often in answers##

  • Release notes for all versions.
  • MATLAB Central File Exchange: a repository of user-contributed MATLAB tools
  • MATLAB Add-Ons: Add-Ons for MATLAB
  • MATLAB Central blogs: usually updated weekly by a number of MathWorks employees
  • Undocumented MATLAB: "Charting MATLAB’s unsupported hidden underbelly"
  • MATLAB Answers: a collaborative environment for getting answers to questions about MathWorks products, similar to Stack Overflow
  • comp.soft-sys.matlab Usenet group: can be accessed online through Google Groups
  • MATLAB Cody™ is a place where you can go to find a variety of MATLAB-based coding challenges that will help to expand your understanding of MATLAB.
  • MATLAB ThingSpeak™ is an open data platform and API for the Internet of Things that enables you to collect, store, analyze, visualize, and act on data gathered directly from sensors or from other web sources. With ThingSpeak and its built-in MATLAB Analysis and MATLAB Visualizations apps, you can create custom trends and plots.
  • MATLAB Online: Online version of MATLAB (available to licensed users only). Octave Online is a free alternative based on the open source GNU Octave which is (pretty much) compatible with MATLAB.
  • MATLAB on Stack Overflow chat: Chat room for users of MATLAB and Octave
94593 questions
45
votes
18 answers

Good practices in writing MATLAB code?

I would like to know the basic principles and etiquette of writing a well structured code.
user238469
45
votes
2 answers

How can I sort a 2-D array in MATLAB with respect to one column?

I would like to sort a matrix according to a particular column. There is a sort function, but it sorts all columns independently. For example, if my matrix data is: 1 3 5 7 -1 4 Then the desired output (sorting by the first column)…
Midhat
  • 17,454
  • 22
  • 87
  • 114
45
votes
6 answers

Matlab Coder vs hand coding?

Some background for people reading this in the future (in case it's not locked). I tend to do my programming in a high level language to understand the problem first. After covering all possible corner cases I proceed to translating the code to C++…
s5s
  • 11,159
  • 21
  • 74
  • 121
44
votes
5 answers

In MATLAB, how do I plot to an image and save the result without displaying it?

This question kind of starts where this question ends up. MATLAB has a powerful and flexible image display system which lets you use the imshow and plot commands to display complex images and then save the result. For example: im =…
Joe Soul-bringer
  • 3,294
  • 5
  • 31
  • 37
44
votes
4 answers

Find given row in a matrix

I have an m by n matrix in MATLAB, say M. I have an n-element row vector, i.e. a one by n column matrix, say X. I know X is a row somewhere in M. How can I find the index in M?
shuhalo
  • 5,732
  • 12
  • 43
  • 60
44
votes
5 answers

How to execute multiple statements in a MATLAB anonymous function?

I'd like to do something like this: >> foo = @() functionCall1() functionCall2() So that when I said: >> foo() It would execute functionCall1() and then execute functionCall2(). (I feel that I need something like the C ,…
Daniel LeCheminant
  • 50,583
  • 16
  • 120
  • 115
44
votes
10 answers

How do I create enumerated types in MATLAB?

Are there enumerated types in MATLAB? If not, what are the alternatives?
iddober
  • 1,254
  • 4
  • 23
  • 43
44
votes
7 answers

How can I find the maximum value and its index in array in MATLAB?

Suppose I have an array, a = [2 5 4 7]. What is the function returning the maximum value and its index? For example, in my case that function should return 7 as the maximum value and 4 as the index.
Yuseferi
  • 7,931
  • 11
  • 67
  • 103
44
votes
2 answers

Why is Octave slower than MATLAB?

I have been using Octave and MATLAB for a few projects, and I've come across a few questions. This question Why/when should I prefer MATLAB over Octave?) answered several, but there is still one lingering... I've read a number of posts/other sources…
Sam Grondahl
  • 2,397
  • 2
  • 20
  • 26
43
votes
9 answers

Generate a random number in a certain range in MATLAB

How can I generate a random number in MATLAB between 13 and 20?
crowso
  • 2,049
  • 9
  • 33
  • 38
43
votes
5 answers

How to visualize correlation matrix as a schemaball in Matlab

I have 42 variables and I have calculated the correlation matrix for them in Matlab. Now I would like to visualize it with a schemaball. Does anyone have any suggestions / experiences how this could be done in Matlab? The following pictures will…
jjepsuomi
  • 4,223
  • 8
  • 46
  • 74
43
votes
6 answers

connected components in OpenCV

I am looking for an OpenCV function that can find connected components and perform a few tasks on them ( like getting the number of pixels, contour, list of pixels in the object etc.. ) Is there a function of OpenCV (C++) that is similar to MatLab's…
EyalG
  • 1,193
  • 3
  • 10
  • 11
42
votes
4 answers

MATLAB, Filling in the area between two sets of data, lines in one figure

I have a question about using the area function; or perhaps another function is in order... I created this plot from a large text file: The green and the blue represent two different files. What I want to do is fill in the area between the red line…
Josh
  • 421
  • 1
  • 4
  • 4
42
votes
8 answers

How to save a plot into a PDF file without a large margin around

If I print a plot in EPS format, the content of the EPS file is fully occupied with the plot. But if I print a plot in PDF format, then there are big margins above and below the plot in the PDF file. How can I save a plot in a PDF file without the…
Tim
  • 1
  • 141
  • 372
  • 590
42
votes
4 answers

Matlab: How to obtain all the axes handles in a figure handle?

How do I obtain all the axes handles in a figure handle? Given the figure handle hf, I found that get(hf, 'children') may return the handles of all axes. However, the Matlab Help suggests that it may return more than just the axes handles: Children…
YYC
  • 1,792
  • 1
  • 14
  • 19