vec=rvec(x) Function to convert any d input to row vector output A general problem arrises because man Matlab functions operate over only 1 dimension, but often one wants them to operate over all dimensions (eg. sum, mean, std etc.). Can get around this by wrapping the operand in a a function that makes it 1D. eg: std(rvec(x)) Another case where this is useful is where one selects ranges of a multi dimensional array and wants the result to come out as a row or column vector in a single step. eg: rvec(img(:,:,3))
0001 function vec=rvec(x) 0002 % vec=rvec(x) 0003 % 0004 % Function to convert any d input to row vector output 0005 % 0006 % A general problem arrises because man Matlab 0007 % functions operate over only 1 dimension, but often 0008 % one wants them to operate over all dimensions 0009 % (eg. sum, mean, std etc.). 0010 % Can get around this by wrapping the operand in a 0011 % a function that makes it 1D. eg: 0012 % 0013 % std(rvec(x)) 0014 % 0015 % Another case where this is useful is where one 0016 % selects ranges of a multi dimensional array and 0017 % wants the result to come out as a row or column vector 0018 % in a single step. eg: 0019 % 0020 % rvec(img(:,:,3)) 0021 0022 vec=x(:)';