dummydn.m
来自「This is matlab sourcecode for measuring 」· M 代码 · 共 22 行
M
22 行
function y=dummydn(x,v,p)
% DUMMYDN
% DUMMYDN(x,v,p) creates a matrix of dummy variables corresponding to the elements of v
% x: Nx1 vector of data to be broken into dummies.
% The pth vector of dummies is deleted so that the dummy matrix is not colinear with a vector of ones.
% v: Kx1 vector specifying the k-1 breakpoints (in ascending order) that
% define the k categories used to construct the dummy variables.
% y: NxK output matrix containing the k dummy variables.
y=[];
[i j]=size(x);
if j~=1
error('x must be a vector')
else
nv=[-Inf; v; +Inf];
for i=2:rows(nv);
t=x<=nv(i) & x>nv(i-1);
y=[y t];
end
y(:,p)=NaN;
y=(packr(y'))';
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?