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
135
votes
17 answers

How do I set default values for functions parameters in MATLAB?

Is it possible to have default arguments in MATLAB? For instance, here: function wave(a, b, n, k, T, f, flag, fTrue=inline('0')) I would like to have the true solution be an optional argument to the wave function. If it is possible, what is the…
Scott
  • 2,551
  • 5
  • 25
  • 25
127
votes
11 answers

Matlab: Running an m-file from command-line

Suppose that; I have an m-file at location: C:\M1\M2\M3\mfile.m And exe file of the matlab is at this location: C:\E1\E2\E3\matlab.exe I want to run this m-file with Matlab, from command-line, for example inside a .bat file. How can I do this, is…
hkBattousai
  • 10,583
  • 18
  • 76
  • 124
123
votes
8 answers

How to elegantly ignore some return values of a MATLAB function

Is it possible to get the 'nth' return value from a function without having to create dummy variables for all n-1 return values before it? Let's say, I have the following function in MATLAB: function [a,b,c,d] = func() a = 1; b = 2; c = 3; d =…
Jordi
  • 5,846
  • 10
  • 40
  • 41
115
votes
7 answers

What is the equivalent of MATLAB's repmat in NumPy

I would like to execute the equivalent of the following MATLAB code using NumPy: repmat([1; 1], [1 1 1]). How would I accomplish this?
vernomcrp
  • 3,459
  • 11
  • 34
  • 44
113
votes
12 answers

How can I apply a function to every row/column of a matrix in MATLAB?

You can apply a function to every item in a vector by saying, for example, v + 1, or you can use the function arrayfun. How can I do it for every row/column of a matrix without using a for loop?
FurtiveFelon
  • 14,714
  • 27
  • 76
  • 97
113
votes
5 answers

Automatically plot different colored lines

I'm trying to plot several kernel density estimations on the same graph, and I want them to all be different colors. I have a kludged solution using a string 'rgbcmyk' and stepping through it for each separate plot, but I start having duplicates…
Doresoom
  • 7,398
  • 14
  • 47
  • 61
110
votes
7 answers

What's the difference between & and && in MATLAB?

What is the difference between the & and && logical operators in MATLAB?
Fantomas
  • 1,495
  • 4
  • 12
  • 21
108
votes
8 answers

How to search for a string in cell array in MATLAB?

Let's say I have the cell array strs = {'HA' 'KU' 'LA' 'MA' 'TATA'} What should I do if I want to find the index of 'KU'?
Benjamin
  • 1,223
  • 2
  • 9
  • 4
107
votes
2 answers

arrayfun can be significantly slower than an explicit loop in matlab. Why?

Consider the following simple speed test for arrayfun: T = 4000; N = 500; x = randn(T, N); Func1 = @(a) (3*a^2 + 2*a - 1); tic Soln1 = ones(T, N); for t = 1:T for n = 1:N Soln1(t, n) = Func1(x(t, n)); end end toc tic Soln2 =…
Colin T Bowers
  • 18,106
  • 8
  • 61
  • 89
104
votes
7 answers

Map function in MATLAB?

I'm a little surprised that MATLAB doesn't have a Map function, so I hacked one together myself since it's something I can't live without. Is there a better version out there? Is there a somewhat-standard functional programming library for MATLAB…
user121550
102
votes
3 answers

Why does numpy std() give a different result to matlab std()?

I try to convert matlab code to numpy and figured out that numpy has a different result with the std function. in matlab std([1,3,4,6]) ans = 2.0817 in numpy np.std([1,3,4,6]) 1.8027756377319946 Is this normal? And how should I handle this?
gustavgans
  • 5,141
  • 13
  • 41
  • 51
102
votes
8 answers

How to get all files under a specific directory in MATLAB?

I need to get all those files under D:\dic and loop over them to further process individually. Does MATLAB support this kind of operations? It can be done in other scripts like PHP,Python...
Gtker
  • 2,237
  • 9
  • 29
  • 37
102
votes
10 answers

reading v 7.3 mat file in python

I am trying to read a matlab file with the following code import scipy.io mat = scipy.io.loadmat('test.mat') and it gives me the following error raise NotImplementedError('Please use HDF reader for matlab v7.3 files') NotImplementedError: Please…
Shan
  • 18,563
  • 39
  • 97
  • 132
95
votes
3 answers

Octave / Matlab: Extend a vector making it repeat itself?

Is there a way to extend a vector by making it repeat itself? >v = [1 2]; >v10 = v x 5; %x represents some function. Something like "1 2" x 5 in perl Then v10 would be: >v10 1 2 1 2 1 2 1 2 1 2 This should work for the general case, not just…
Tom
  • 43,810
  • 29
  • 138
  • 169
92
votes
5 answers

Setting graph figure size

All I want to do is make the width greater and the height smaller. I'm just doing raster plots but this question applies to any MATLAB figure. I can manually resize it using the figure directly when it's created but I want the program to spit it…
ale
  • 11,636
  • 27
  • 92
  • 149