0001 function [y,tw]=nt_wpwr(x,w)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 if nargin<2; w=[]; end
0012
0013 if iscell(x);
0014 if ~isempty(w); error('not implemented'); end
0015 y=0; tw=0;
0016 for iTrial=1:numel(x)
0017 y=y+nt_wpwr(x{iTrial});
0018 tw=tw+size(x{iTrial},1);
0019 end
0020 return;
0021 end
0022
0023 x=nt_unfold(x);
0024 w=nt_unfold(w);
0025
0026 if isempty(w)
0027 y=sum(x(:).^2);
0028 tw=numel(x);
0029 else
0030 x=nt_vecmult(x,w);
0031 y=sum(x(:).^2);
0032 tw=sum(w(:));
0033 end
0034
0035 if nargout==0;
0036 disp(num2str(y));
0037 clear y tweight
0038 end