%USAGE	B = mvo( A, V {,op=':*'} )
%
%	matrix-by-vector binary operation
%
%A	matrix
%V	vector	   --- COMPATIBILITY CONDITION ---
%	( I) ROW : length ( V ) equals columns( A )
%	     then  element V(j) operates on  A(:,j) 
%	(II) COL : length ( V ) equals    rows( A )
%	     then  element V(j) operates on  A(j,:) 
%op	operator one of ':*',':/',':+',':-',':^',':|',':&',':**',':\\'
%
%EXAS	(I)  B = mvo ( A, ROW V, ':+')
%	     A = [ A11, A12, A13 ]	B = [ A11+V1, A12+V2, A13+V3 ]
%	         [ A21, A22, A23 ]	    [ A21+V1, A22+V2, A23+V3 ]
%	            +    +    +		      corresponding element of V
%	     V = [ V1 , V2 , V3  ]	      added to each column  of A
%
%	(II) B = mvo ( A, COL V, ':/')	same A as above
%	     compatible COL V must have 2 elements V=[V1;V2]
%	     B = [ A11/V1 , A12/V1, A13/V1 ]  corresponding element of V
%		 [ A21/V2 , A22/V2, A23/V2 ]  divides each row of  mat A
%										
%NOTE	 -  op=':*' by default multiplication 
%	 -  escaped backslash  operator necessary
%AUTHOR	(c) Rolf Fabian 000121V <fabian@tu-cottbus.de>

function B=mvo(A,V,op)

	ft='mvo error: ';
	et='... quit.\n';
	m0='nargin ';
	m1='unknown operator ';
	m2='incompatible size V ';

	if	(nargin<2||nargin>3)
		fprintf(stderr,"%s%s%s",ft,m0,et); 
		B=[]; return;
	end

	if	(nargin<3) op=':*';  end

	[ra,ca]=size( A);
	[rv,cv]=size( V);
	[ro,co]=size(op);

	%translate the only (non-escaped) 3 char op ':**' to equivalent 2 chars
	if	( ro==1&&co==3&&op==':**')
		op=':^'; co=2;
	end

	if	( ro!=1||co>2||op(1)!=':'||\
		  all(toascii(['*','/','+','-','^','|','&','\\'])-toascii(op(2))) )
		fprintf(stderr,"%s%s'%s'%s",ft,m1,op,et);
		B=[]; return;
	end

	if	(op==':&'||op==':|')
		 op=op(2);			%V2.0.13: '.&' and '.|' fail
	else     op=['.',op(2)];
	end

	B 	= A*NaN; 			%init output at same size

	if	(rv==1&&cv==ca)			%ROW V
		for j=1:ca
			eval(sprintf('B(:,j)=A(:,j) %s V(j);',op));
		end
	elseif	(cv==1&&rv==ra)			%COL V
		for j=1:ra
			eval(sprintf('B(j,:)=A(j,:) %s V(j);',op));
		end
	else	
		fprintf(stderr,"%s%s[%d,%d] %s",ft,m2,rv,cv,et);
		B=[];
	end
end

