1function [err, Qd, dfx, dmat2] = QRDecom(dmat, cmat) 2% 3% [err,] = QRDecom.m () 4% 5%Purpose: 6% 7% 8% 9%Input Parameters: 10% 11% 12% 13%Output Parameters: 14% err : 0 No Problem 15% : 1 Problems 16% 17% 18% 19%Key Terms: 20% 21%More Info : 22% 23% 24% 25% 26% Author : Gang Chen 27% Date : Tue Mar 23 16:09:23 EST 2004 28% SSCC/NIMH/ National Institutes of Health, Bethesda MD 20892 29 30 31%Define the function name for easy referencing 32FuncName = 'QRDecom.m'; 33 34%Debug Flag 35DBG = 1; 36 37%initailize return variables 38err = 1; 39 40% Tolerance for computing rank from diag(R) after QR decomposition 41%[nrows,ncols] = size(dmat); 42 43% Find the null space of the constraints matrix 44[Qc,Rc,Ec] = qr(cmat'); 45pc = Rrank(Rc); 46Qc0 = Qc(:,pc+1:end); 47 48% Do qr decomposition on design matrix projected to null space 49Dproj = dmat*Qc0; 50[Qd,Rd,Ed] = qr(Dproj,0); 51dfx = Rrank(Rd); 52Qd = Qd(:,1:dfx); 53%Rd = Rd(1:dfx,1:dfx); 54 55% Return reduced design matrix if requested 56if nargout>3 57 dmat2 = Qd' * dmat; 58end 59 60err = 0; 61return; 62