/*------------------------------------------------------------------------------* * File Name: SetCellsOutsideCircle * * Creation: * * Purpose: Programming Example * * Copyright (c) OriginLab Corp.2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 * * All Rights Reserved * * * * Modification Log: * *------------------------------------------------------------------------------*/ #include ///////////////////////////////////////////////////////////////////////////////// // This example shows how to set all cells outside of a circular area in a // matrix to a particular value. // // NOTE: It is assumed that a square matrix is active. // // void set_cells_outside_circle(double dOutsideVal = 0) { // Declare matrix layer and check validity MatrixLayer ml = Project.ActiveLayer(); if( !ml ) { out_str("Active layer is not a matrix"); return; } // Declare matrix object and get dimensions Matrix mm(ml); int nRows = mm.GetNumRows(); int nCols = mm.GetNumCols(); if( nRows != nCols ) { out_str("Matrix is not a square matrix"); return; } int nrc = 0.5 + nRows/2.0; // nearest int int ncc = 0.5 + nCols/2.0; double rr = min(nrc, ncc); // Loop over all cells for(int nr = 0; nr < nRows; nr++) { for(int nc = 0; nc < mm.GetNumCols(); nc++) { double xsqr = (nr - nrc)^2; double ysqr = (nc - ncc)^2; if(sqrt(xsqr + ysqr) > rr) { mm[nr][nc] = dOutsideVal; } } } } /////////////////////////////////////////////////////////////////////////////////