Home > SaliencyToolbox > safeDivide.m

safeDivide

PURPOSE ^

safeDivide - divides two arrays, checking for 0/0.

SYNOPSIS ^

function result = safeDivide(arg1,arg2)

DESCRIPTION ^

 safeDivide - divides two arrays, checking for 0/0.

 result = safeDivide(arg1,arg2)
    returns arg1./arg2, where 0/0 is assumed to be 0 instead of NaN.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % safeDivide - divides two arrays, checking for 0/0.
0002 %
0003 % result = safeDivide(arg1,arg2)
0004 %    returns arg1./arg2, where 0/0 is assumed to be 0 instead of NaN.
0005 
0006 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2013
0007 % by Dirk B. Walther and the California Institute of Technology.
0008 % See the enclosed LICENSE.TXT document for the license agreement.
0009 % More information about this project is available at:
0010 % http://www.saliencytoolbox.net
0011 
0012 function result = safeDivide(arg1,arg2)
0013 
0014 ze = (arg2 == 0);
0015 arg2(ze) = 1;
0016 result = arg1./arg2;
0017 result(ze) = 0;

Generated on Thu 18-Jul-2013 06:10:46 by m2html © 2005