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
74
votes
4 answers

Optional args in MATLAB functions

How can I declare function in MATLAB with optional arguments? For example: function [a] = train(x, y, opt), where opt must be an optional argument.
Yekver
  • 4,985
  • 7
  • 32
  • 49
74
votes
7 answers

How can I count the number of elements of a given value in a matrix?

Does anyone know how to count the number of times a value appears in a matrix? For example, if I have a 1500 x 1 matrix M (vector) which stores the values of weekdays (1 - 7), how could I count how many Sundays (1), Mondays(2), ... , Saturdays(7)…
Niko Gamulin
  • 66,025
  • 95
  • 221
  • 286
73
votes
2 answers

In MATLAB, are variables REALLY double-precision by default?

This question arose out of something strange that I noticed after investigating this question further... I always understood MATLAB variables to be double-precision by default. So, if I were to do something like declare a variable with 20 digits…
gnovice
  • 125,304
  • 15
  • 256
  • 359
73
votes
4 answers

Function for 'does matrix contain value X?'

Is there a built in MATLAB function to find out if a matrix contains a certain value? (ala PHP's in_array())
zenna
  • 9,006
  • 12
  • 73
  • 101
73
votes
31 answers

What is your favourite MATLAB/Octave programming trick?

I think everyone would agree that the MATLAB language is not pretty, or particularly consistent. But nevermind! We still have to use it to get things done. What are your favourite tricks for making things easier? Let's have one per answer so people…
Matt
  • 5,522
  • 5
  • 29
  • 24
72
votes
15 answers

How to deal with name/value pairs of function arguments in MATLAB

I have a function that takes optional arguments as name/value pairs. function example(varargin) % Lots of set up stuff vargs = varargin; nargs = length(vargs); names = vargs(1:2:nargs); values = vargs(2:2:nargs); validnames = {'foo', 'bar', 'baz'};…
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
71
votes
6 answers

Why is 24.0000 not equal to 24.0000 in MATLAB?

I am writing a program where I need to delete duplicate points stored in a matrix. The problem is that when it comes to check whether those points are in the matrix, MATLAB can't recognize them in the matrix although they exist. In the following…
Kamran Bigdely
  • 7,946
  • 18
  • 66
  • 86
67
votes
4 answers

How do I get the handles of all open figures in MATLAB

I have nine open figures in matlab (generated by another function) and I want to print them all to file. Does anyone know how to grab the handles of all open figures in MATLAB? I know about gcf but it doesn't seem to do what I want.
Liz
  • 673
  • 1
  • 5
  • 4
66
votes
9 answers

MATLAB-style find() function in Python

In MATLAB it is easy to find the indices of values that meet a particular condition: >> a = [1,2,3,1,2,3,1,2,3]; >> find(a > 2) % find the indecies where this condition is true [3, 6, 9] % (MATLAB uses 1-based indexing) >> a(find(a >…
user344226
  • 663
  • 1
  • 5
  • 5
66
votes
7 answers

Concatenating empty array in Numpy

in Matlab I do this: >> E = []; >> A = [1 2 3 4 5; 10 20 30 40 50]; >> E = [E ; A] E = 1 2 3 4 5 10 20 30 40 50 Now I want the same thing in Numpy but I have problems, look at this: >>> E =…
maxv15
  • 1,057
  • 2
  • 9
  • 9
64
votes
4 answers

Faster way to initialize arrays via empty matrix multiplication? (Matlab)

I've stumbled upon the weird way (in my view) that Matlab is dealing with empty matrices. For example, if two empty matrices are multiplied the result is: zeros(3,0)*zeros(0,3) ans = 0 0 0 0 0 0 0 0 0 Now, this already…
bla
  • 25,846
  • 10
  • 70
  • 101
63
votes
9 answers

SQL server stored procedure return a table

I have a stored procedure that takes in two parameters. I can execute it successfully in Server Management Studio. It shows me the results which are as I expect. However it also returns a Return Value. It has added this line, SELECT 'Return Value'…
mHelpMe
  • 6,336
  • 24
  • 75
  • 150
63
votes
2 answers

Loop through files in a folder in matlab

I have a set of days of log files that I need to parse and look at in matlab. The log files look like this: LOG_20120509_120002_002.csv (year)(month)(day)_(hour)(minute)(second)_(log part number) The logs increment hourly, but sometimes the…
Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
63
votes
7 answers

find length of sequences of identical values in a numpy array (run length encoding)

In a pylab program (which could probably be a matlab program as well) I have a numpy array of numbers representing distances: d[t] is the distance at time t (and the timespan of my data is len(d) time units). The events I'm interested in are when…
Gyom
  • 3,773
  • 5
  • 29
  • 38
61
votes
8 answers

Parfor for Python

I am looking for a definitive answer to MATLAB's parfor for Python (Scipy, Numpy). Is there a solution similar to parfor? If not, what is the complication for creating one? UPDATE: Here is a typical numerical computation code that I need speeding…
Dat Chu
  • 10,822
  • 13
  • 58
  • 82