|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function ind=lookup(tabvals,x,endadj);
|
|
|
| global CompEcon_MEXwarned
|
|
|
| if isempty(CompEcon_MEXwarned)
|
| disp('Warning: You are using the m-file version of a function that is coded as a C Mex file.')
|
| disp(' Running this M file version may be significantly slower and more memory intensive.')
|
| disp(' Use MEXALL to create the executable (MEX or DLL) and make sure it is on the MATLAB path.')
|
| CompEcon_MEXwarned=1;
|
| end
|
|
|
|
|
| if nargin<2
|
| error('At least two parameters must be specified');
|
| end
|
| if nargin<3 endadj=0; end
|
| if isempty(endadj) endad=0; end
|
|
|
| n=prod(size(x));
|
| if min(size(tabvals))>1
|
| error('tabvals must be a vector');
|
| else
|
| tabvals=tabvals(:);
|
| if any(diff(tabvals)<0)
|
| error('tabvals must be sorted in ascending order')
|
| end
|
| end
|
| m=length(tabvals);
|
| if endadj>=2, m=m-length(find(tabvals==tabvals(end))); end
|
|
|
| [temp,ind]=sort([tabvals(1:m); x(:)]);
|
| temp=find(ind>m);
|
| j=ind(temp)-m;
|
| ind=reshape(temp-(1:n)',size(x));
|
| ind(j)=ind(:);
|
|
|
| if endadj==1 | endadj==3
|
| ind(ind==0)=length(find(tabvals==tabvals(1)));
|
| end
|
| |