Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of matrix length

Tags:

matrix

matlab

Matlab defines the matrix function length to return

Length of largest array dimension

What is an example of a use of knowing the largest dimension? Knowing number of rows or columns has obvious uses... but I don't know why someone would want the largest dimension regardless of whether it is rows or cols.

Thank You

like image 539
Max Wen Avatar asked Mar 18 '23 12:03

Max Wen


1 Answers

In fact, most of my code wants to do things exactly once for each row, for each column or for each element.

Therefore, I typically use one of these

size(M,1)
size(M,2)
numel(V)

In particular do not depend on length to match the number of elements in a vector!

The only real convenience that I found {in older versions of matlab} for length is if I need a repeat statement rather than a while. Then it is convenient that length of vectors usually returns at least one.

Some other uses that I had for length:

  • A quick rough check whether something is big.
  • Making something square as mentioned by @Mike
like image 200
Dennis Jaheruddin Avatar answered Mar 24 '23 16:03

Dennis Jaheruddin