As mentioned in @Gunther's comments above, a common function to handle simple conditions to simulate a tertiary operator ?: can be created to bypass the restriction that Matlab does not allow conventions inside anon functions (unless you think this messy-ugly-inefficient, but fun built-in version :).
The solution was presented at this link (and, possibly, in several other places, but SO returned to my Google search, so I thought it would be nice to add here). http://www.mathworks.co.jp/matlabcentral/newsreader/view_thread/158054
define a function: iff or ifelse and add it to the Matlab path.
function result = ifelse(condition,trueResult,falseResult) error(nargchk(3,3,nargin)); % check correct number of input args if condition result = trueResult; else result = falseResult; end
then use like this
predict = arrayfun(@(x) ifelse(x>=0.5,1,0), inputData);
In the case of OP, something like this can be used
arrayfun(@(x) ifelse(abs(x)<3,x^.2,0), data)
source share