Prev Next ones

Matrix of Ones

Syntax
Matlab or Octave x = ones(mn)
C++ scalar_matrix<double> x(mn, 1.)

Matlab or Octave
If m and n are integer scalars, the Matlab or Octave syntax
     
x = ones(mn)
sets x to an @(@ m \times n @)@ matrix with all its elements equal to one.

Example
     function [ok] = ones_ok()
     ok      = true;
     m       = 2;
     n       = 3;
     % -------------------
     x       = ones(2, 3);
     % -------------------
     [m, n]  = size(x);
     ok      = ok & (m == 2);
     ok      = ok & (n == 3);
     ok      = ok & all( all( x == 1 ) );
     return


C++
The corresponding C++ syntax is
     scalar_matrix<double> 
x(mn, 1.)
where m and n are size_t objects and x is an @(@ m \times n @)@ ublas matrix<double> object.

Example
     # include <mat2cpp.hpp>
     bool ones_ok(void)
     {	bool   ok  = true;
     	using namespace mat2cpp;
     
     	size_t i, j, m(2), n(3);
     	// -------------------------------
     	scalar_matrix<double> x(m, n, 1.);
     	// -------------------------------
     	ok &= (x.size1() == m);
     	ok &= (x.size2() == n);
     	for(i = 0; i < m; i++)
     	{	for(j = 0; j < n; j++)
     			ok &= (x(i,j) == 1.);
     	}
     	return ok;
     }


Input File: omh/ones.omh