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
10
votes
3 answers

Replacing all NaNs with zeros without looping through the whole matrix?

I had an idea to replace all the NaNs in my matrix by looping through each one and using isnan. However, I suspect this will make my code run more slowly than it should. Can someone provide a better suggestion?
10
votes
2 answers

Why would saving to a folder called temp cause data loading to slow down in a for loop in Matlab?

IMPORTANT UPDATE I just made the discovery that after restarting Matlab and the computer, this simplified code no longer reproduces the problem for me either... I am so sorry for taking up your time with a script that didn't work. However, the old…
LaWa
  • 183
  • 7
10
votes
7 answers

matlab export plot to vector format

All the time previously I was exporting Matlab figures in a raster format (JPG, PNG) Is there a way to export a plot from Matlab in a vector format (SVG). I need it to inset that plots into LaTeX document. The only thing, I have found so far is a…
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
10
votes
4 answers

Find closest point in matlab grid

G'day I'm trying to program a smart way to find the closest grid points to the points along a contour. The grid is a 2-dimensional grid, stored in x and y (which contain the x and y kilometre positions of the grid cells). The contour is a line, made…
David_G
  • 1,127
  • 1
  • 16
  • 36
10
votes
3 answers

Custom x-axis values in a matlab plot

Currently when I plot a 9 by 6 array, the x-axis of the figure is just 1, 2, 3 up to 9. The Y-axis shows the correct values. Instead of 1 to 9 I would like the x-axis values to be custom. They should be 100 200 400 1000 2000 5000 10000 20000…
Devon
  • 393
  • 2
  • 5
  • 17
10
votes
4 answers

How can I use MATLAB arrays as keys to the HashMap java objects?

The put function works fine but the get function does not. Apparently I don't know the trick. >> X = [ 1, 2, 3]; >> M = java.util.HashMap; >> M.put(X,1); >> M.get([1,2,3]) ans = [] I have searched and read many posts but could not find a solution…
user165466
10
votes
3 answers

Change row vector to column vector

How can I change this into a column, at the moment all 750 entries are on one row? p = normal(1:750)-1; I have tried: columns = 1; p = normal(1:750)-1; p = p(1:columns); I have also tried: rows = 1000; p = normal(1:750)-1; p = p(1:rows)';
G Gr
  • 6,030
  • 20
  • 91
  • 184
10
votes
5 answers

How to fit a gaussian to data in matlab/octave?

I have a set of frequency data with peaks to which I need to fit a Gaussian curve and then get the full width half maximum from. The FWHM part I can do, I already have a code for that but I'm having trouble writing code to fit the Gaussian. Does…
user1806676
  • 169
  • 1
  • 1
  • 10
10
votes
2 answers

Draw a line through two points

Using MatLab, I know how to create a line segment connecting two points using this code: line([0 1],[0 1]) This draws a straight line segment from the point (0,0) to the point (1,1). What I am trying to do is continue that line to the edge of the…
CodeFusionMobile
  • 14,812
  • 25
  • 102
  • 140
10
votes
1 answer

Finding unique permutations efficiently

I have the following problem. I need to compute the permutations of a set; however, the set may contain two elements which are the same and therefore cause repeated permutations. For example: Given the set [ 0 0 1 2 ], the permutations include…
devrobf
  • 6,973
  • 2
  • 32
  • 46
10
votes
5 answers

Matlab - how to make a custom legend

I have the following picture : And I would like to make a legend for it. Basically, I want to make a legend for each type of rectangle. In the legend box, I want to mark each color line according to the type of body which it marks: green line :…
Simon
  • 4,999
  • 21
  • 69
  • 97
10
votes
4 answers

Interpolate surface of 3D cylinder in Matlab

I have a dataset that describes a point cloud of a 3D cylinder (xx,yy,zz,C): and I would like to make a surface plot from this dataset, similar to this In order to do this I thought I could interpolate my scattered data using TriScatteredInterp…
space-dementia
  • 307
  • 1
  • 5
  • 10
10
votes
6 answers

MATLAB "out of memory" error

When I run a sample script in MATLAB, it says: Out of memory. Type HELP MEMORY for your options. When I type "memory", it reports: Maximum possible array: 156 MB (1.638e+008 bytes) * Memory available for all arrays: 740 MB…
Contango
  • 76,540
  • 58
  • 260
  • 305
10
votes
3 answers

Profiling a mex-function

I have just rewritten a Matlab program in c++ as a mex-function to speed things up, with fantastic results. This optimization decision was a very very good idea, with up to a factor 20 speed up without threading. It still left me curious about what…
AnnaR
  • 3,166
  • 6
  • 35
  • 39
10
votes
2 answers

read text files containing binary data as a single matrix in matlab

I have a text file which contains binary data in the following…
user1716595
  • 151
  • 1
  • 6