![]() |
Prev | Next |
Matlab or Octave |
y = max( max( x) )
|
C++ |
y = max( x)
|
y = max( max(
x) )
sets y to the maximum element in the matrix x.
If either m or n is equal to one,
y = max(
x)
also sets y to the maximum element in the matrix x.
function [ok] = max_ok()
ok = true;
m = 2;
n = 3;
x = rand(m, n);
% ------------------
y = max( max(x) );
% ------------------
[m, n] = size(y);
ok = ok & (m == 1) & (n == 1);
ok = ok & all( all ( x <= y ) );
ok = ok & ~ all( all ( x < y ) );
return
y = max(
x)
where x is a non-empty
(non-zero row and column size)
ublas matrix<double>
object
and y is a double
.
# include <mat2cpp.hpp>
bool max_ok(void)
{ bool ok = true;
using namespace mat2cpp;
size_t i, j, m(2), n(3);
matrix<double> x = rand(m, n);
// ---------------
double y = max(x);
// ---------------
bool less = true;
for(i = 0; i < m; i++)
{ for(j = 0; j < n; j++)
{ ok &= x(i,j) <= y;
less &= x(i,j) < y;
}
}
ok &= ! less;
return ok;
}