예제 #1
0
/*!
  Insert a row vector.
  \param i : Index of the first element to introduce. This index starts from 0.
  \param v : Row vector to insert.

  The following example shows how to use this function:
  \code
#include <visp/vpRowVector.h>

int main()
{
  vpRowVector v(4);
  for (unsigned int i=0; i < v.size(); i++)
    v[i] = i;
  std::cout << "v: " << v << std::endl;

  vpRowVector w(2);
  for (unsigned int i=0; i < w.size(); i++)
    w[i] = i+10;
  std::cout << "w: " << w << std::endl;

  v.insert(1, w);
  std::cout << "v: " << v << std::endl;
}  \endcode
  It produces the following output:
  \code
v: 0  1  2  3
w: 10  11
v: 0  10  11  3
  \endcode
 */
void vpRowVector::insert(unsigned int i, const vpRowVector &v)
{
  if (i+v.size() > this->size())
    throw(vpException(vpException::dimensionError,
                      "Unable to insert (1x%d) row vector in (1x%d) row vector at position (%d)",
                      v.getCols(), colNum, i));
  for (unsigned int j=0; j < v.size(); j++)
    (*this)[i+j] = v[j];
}
예제 #2
0
/*!
  Compute the median value of all the elements of the vector.
*/
double
vpRowVector::median(const vpRowVector &v)
{
  if (v.data==NULL) {
    throw(vpException(vpException::fatalError,
                      "Cannot compute mean value of an empty row vector"));
  }

  std::vector<double> vectorOfDoubles(v.size());
  for(unsigned int i = 0; i < v.size(); i++) {
    vectorOfDoubles[i] = v[i];
  }

  return vpMath::getMedian(vectorOfDoubles);
}
예제 #3
0
/*!
  Compute the standard deviation value of all the elements of the vector.
*/
double
vpRowVector::stdev(const vpRowVector &v, const bool useBesselCorrection)
{
  if (v.data==NULL) {
    throw(vpException(vpException::fatalError,
                      "Cannot compute mean value of an empty row vector"));
  }

  double mean_value = mean(v);
  double sum_squared_diff = 0.0;
  for(unsigned int i = 0; i < v.size(); i++) {
    sum_squared_diff += (v[i]-mean_value) * (v[i]-mean_value);
  }

  double divisor = (double) v.size();
  if(useBesselCorrection && v.size() > 1) {
    divisor = divisor-1;
  }

  return std::sqrt(sum_squared_diff / divisor);
}