MATLAB: Function for Script. I need to write a Function that selects the positive and negative numbers from a matrix. How to write this

function;scriptmatrixnegativepositive

I need to write a Function that selects the positive and negative numbers from a matrix. How to write this?

Best Answer

function [p,n]=splitsigns(x)
% return positive/negative values from array x in vectors p/n, respectively
p=x(x>0);
n=x(x<0);
This one excludes 0; pick where you want those if do...