Prev Next size

Matrix Size

Syntax
Matlab or Octave [mn] = size(x)
C++ m = x.size1()
n = x.size2()

Matlab or Octave
If x is a matrix, the Matlab or Octave syntax
     [
mn] = size(x)
returns the row dimension m and column dimension n of the matrix x.

Example
     function [ok] = size_ok()
     ok      = true;
     x       = [ 1 2 3 ; 4 5 6 ];
     % ----------------
     [m, n]  = size(x);
     % ----------------
     ok      = ok & (m == 2);
     ok      = ok & (n == 3);
     return


C++
The corresponding C++ syntax is
     
m = x.size1()
     
n = x.size2()
where x is a ublas matrix<double> and m, n are size_t objects.

Example
     # include <mat2cpp.hpp>
     bool size_ok(void)
     {	bool   ok  = true;
     	using namespace mat2cpp;
     
     	size_t m(2), n(3);
     	matrix<double> x(m, n);
     	// --------------------
     	ok &= (x.size1() == m);
     	ok &= (x.size2() == n);
     	// --------------------
     	return ok;
     }


Input File: omh/size.omh