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
558
votes
16 answers

Read .mat files in Python

Is it possible to read binary MATLAB .mat files in Python? I've seen that SciPy has alleged support for reading .mat files, but I'm unsuccessful with it. I installed SciPy version 0.7.0, and I can't find the loadmat() method.
Gilad Naor
  • 20,752
  • 14
  • 46
  • 53
398
votes
9 answers

How can I index a MATLAB array returned by a function without first assigning it to a local variable?

For example, if I want to read the middle value from magic(5), I can do so like this: M = magic(5); value = M(3,3); to get value == 13. I'd like to be able to do something like one of these: value = magic(5)(3,3); value = (magic(5))(3,3); to…
Joe Kearney
  • 7,397
  • 6
  • 34
  • 45
288
votes
10 answers

Representing and solving a maze given an image

What is the best way to represent and solve a maze given an image? Given an JPEG image (as seen above), what's the best way to read it in, parse it into some data structure and solve the maze? My first instinct is to read the image in pixel by…
Whymarrh
  • 13,139
  • 14
  • 57
  • 108
287
votes
9 answers

Differences between Octave and MATLAB

I'm a programmer who knows Python, Ruby and some C who is trying to decide whether to learn GNU Octave or MATLAB. I know that they have a lot in common, but it isn't clear to me how similar the syntax is or even the data structures are. The above…
lswim
  • 3,064
  • 2
  • 15
  • 13
231
votes
4 answers

xkcd style graphs in MATLAB

So talented people have figured out how to make xkcd style graphs in Mathematica, in LaTeX, in Python and in R already. How can one use MATLAB to produce a plot that looks like the one above? What I have tried I created wiggly lines, but I couldn't…
bla
  • 25,846
  • 10
  • 70
  • 101
226
votes
9 answers

Is it possible to define more than one function per file in MATLAB, and access them from outside that file?

When I was studying for my undergraduate degree in EE, MATLAB required each function to be defined in its own file, even if it was a one-liner. I'm studying for a graduate degree now, and I have to write a project in MATLAB. Is this still a…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
205
votes
12 answers

Why is MATLAB so fast in matrix multiplication?

I am making some benchmarks with CUDA, C++, C#, Java, and using MATLAB for verification and matrix generation. When I perform matrix multiplication with MATLAB, 2048x2048 and even bigger matrices are almost instantly multiplied. …
Wolf
  • 3,117
  • 3
  • 19
  • 10
197
votes
6 answers

How to get the type of a variable in MATLAB

Does MATLAB have a function/operator that indicates the type of a variable (similar to the typeof operator in JavaScript)?
Dónal
  • 185,044
  • 174
  • 569
  • 824
179
votes
9 answers

Is there a foreach in MATLAB? If so, how does it behave if the underlying data changes?

Is there a foreach structure in MATLAB? If so, what happens if the underlying data changes (i.e. if objects are added to the set)?
Kip
  • 107,154
  • 87
  • 232
  • 265
176
votes
2 answers

A tool to convert MATLAB code to Python

I have a bunch of MATLAB code from my MS thesis which I now want to convert to Python (using numpy/scipy and matplotlib) and distribute as open-source. I know the similarity between MATLAB and Python scientific libraries, and converting them…
Jack_of_All_Trades
  • 10,942
  • 18
  • 58
  • 88
152
votes
14 answers

What is the Python equivalent of Matlab's tic and toc functions?

What is the Python equivalent of Matlab's tic and toc functions?
Alex
  • 2,145
  • 3
  • 19
  • 19
152
votes
4 answers

Is MATLAB OOP slow or am I doing something wrong?

I'm experimenting with MATLAB OOP, as a start I mimicked my C++'s Logger classes and I'm putting all my string helper functions in a String class, thinking it would be great to be able to do things like a + b, a == b, a.find( b ) instead of strcat(…
stijn
  • 34,664
  • 13
  • 111
  • 163
145
votes
9 answers

Using i and j as variables in MATLAB

i and j are very popular variable names (see e.g., this question and this one). For example, in loops: for i=1:10, % Do something... end As indices into a matrix: mat(i, j) = 4; Why shouldn't they be used as variable names in MATLAB?
Shai
  • 111,146
  • 38
  • 238
  • 371
136
votes
11 answers

What can MATLAB do that R cannot do?

I often hear people complain how expensive MATLAB licenses are. Then I wonder why they don't just use Octave or R. But is the latter right? Can you use R to replace MATLAB?
Frank
  • 64,140
  • 93
  • 237
  • 324
136
votes
5 answers

In MATLAB, when is it optimal to use bsxfun?

I've noticed that a lot of good answers to MATLAB questions on Stack Overflow frequently use the function bsxfun. Why? Motivation: In the MATLAB documentation for bsxfun, the following example is provided: A = magic(5); A = bsxfun(@minus, A,…
Colin T Bowers
  • 18,106
  • 8
  • 61
  • 89
1
2 3
99 100