Matlab

MATLAB is a high-level language and interactive programming environment for numerical computation and visualization developed by MathWorks. Questions should be tagged with either [tag:matlab] or [tag:octave], but not both, unless the question explicitly involves both packages. When using this tag, please mention the MATLAB release you're working with (e.g. R2017a).

56 votes
8 answers
2.2K views
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 su

avatar
Scot
0 1 0 9
asked 07 September, 2021
63 votes
2 answers
2K views
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^

avatar
Yolando
0 1 0 9
asked 07 September, 2021
52 votes
8 answers
1.3K views
How to search for a string in cell array in MATLAB?

Let's say I have the cell array strs = {'HA' 'KU' 'LA' 'MA' &ap

avatar
Winford
0 1 0 9
asked 07 September, 2021
55 votes
11 answers
848 views
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

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
59 votes
5 answers
1.4K views
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 differ

avatar
Dusty
0 1 0 9
asked 07 September, 2021
57 votes
10 answers
1.5K views
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 locatio

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
61 votes
8 answers
1.2K views
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 variable

avatar
Carmelina
0 1 0 9
asked 07 September, 2021
57 votes
16 answers
1.4K views
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,

avatar
Elicia
0 1 0 9
asked 07 September, 2021
57 votes
5 answers
607 views
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 functio

avatar
Suzan
0 1 0 9
asked 07 September, 2021
56 votes
9 answers
1.9K views
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

avatar
Rudolf
0 1 0 9
asked 07 September, 2021
59 votes
4 answers
2.6K views
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 puttin

avatar
Benton
0 1 0 9
asked 07 September, 2021
59 votes
9 answers
996 views
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 a

avatar
Dario
0 1 0 9
asked 07 September, 2021
56 votes
6 answers
3.1K views
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

avatar
Boyd
0 1 0 9
asked 07 September, 2021
51 votes
12 answers
1.9K views
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.

avatar
Wei
0 1 0 9
asked 07 September, 2021
60 votes
9 answers
832 views
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

avatar
Majorie
0 1 0 9
asked 07 September, 2021
49 votes
4 answers
1.9K views
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

avatar
Don
0 1 0 9
asked 07 September, 2021
68 votes
9 answers
460 views
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

avatar
Rudy
0 1 0 9
asked 07 September, 2021