Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

matrix

matlab

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?

like image 617
gerrit Avatar asked Dec 03 '12 08:12

gerrit


People also ask

What does empty mean in MATLAB?

example. TF = isempty( A ) returns logical 1 ( true ) if A is empty, and logical 0 ( false ) otherwise. An empty array, table, or timetable has at least one dimension with length 0, such as 0-by-0 or 0-by-5.

How do you define an empty matrix?

An empty matrix has no rows and no columns. A matrix that contains missing values has at least one row and column, as does a matrix that contains zeros. The J function in SAS/IML software creates a matrix that has a specified number of rows and columns and fills the matrix with a constant value.

Is string empty MATLAB?

Strings always contain the empty string as a substring.

How do you empty a cell in MATLAB?

Like all MATLAB® arrays, cell arrays are rectangular, with the same number of cells in each row. myCell is a 2-by-3 cell array. You also can use the {} operator to create an empty 0-by-0 cell array. To add values to a cell array over time or in a loop, create an empty N -dimensional array using the cell function.


1 Answers

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.

like image 131
bla Avatar answered Oct 23 '22 18:10

bla