What does the empty `()` do on a Matlab matrix?

matlab, matrix

Solution

Besides the fact the it would give the default operation on some function, such as `rand()`, and easter eggs such as `imagesc()` and `spy()` (this will work also without the `()`) , it seems to be a more efficient way to access whole arrays as long as their dimensionality is below 5 (as @Rody Oldenhuis spotted) . For example:

a=rand(2^12);

tic
for j=1:1e5
a ;
end
toc

tic
for j=1:1e5
a(:)  ;
end
toc

tic
for j=1:1e5
a()   ; 
end
toc

yield:

Elapsed time is 0.047250 seconds.
Elapsed time is 0.022260 seconds.
Elapsed time is 0.011925 seconds.

However, for assignments there's very little difference between `a1=a` vs `a1=a()`, where the latter is slower by 1.5%...

Perhaps this thread will answer some of your question regarding operator overloading.

Problem

In `Matlab`, what exactly does the expression `M()` do where `M` is a matrix? ``` >> M = magic(3); >> M() ans = 8 1 6 3 5 7 4 9 2 ``` Is the expression `isequaln(M, M())` true under all circumstances? Is `M()` simply a copy of `M`, or an identical expression, or is there any context where referring to `M()` means something else than referring to `M`? Maybe in the case of operator overloading?

Original source