Deleting some columns of matrix and obtain the original column index.
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
Dear friends
I need really some help/advice. My problem is stated as follows.
The original data is a X=100*50 matrix. The dependent variable is a y=100*1 vector.
Step 1: I regress y on X and get the regression coefficient "b". (The statistic toolbox)
Step 2: Sorting the coefficient "b" and get the index "I".
Step 3: Delete the first column denoted by "I" and get the new matrix X.
Step 4: Repeat the procedures Step 1 -Step 3 20 times until the new matrix X contains only 100*30.
Step 5: How can use the for loop to get the original index of the new matrix X?
For example, let X be a 9*5 matrix and y=ones(9,1). My codes for "2 runs" are as follows:
 X=[4   8   11   10   14;  12   9   8   12   13;  10   5   7   10   13; 
   25   16   5   7   7 ;  12   7   8   17   12;  18   15   13   18   31;
    7   5   4   35   16;  6    14   10   15   4 ;   8   11   8   11   10]
Step 1:
 [b,bint,r] = regress(y,X);   %regress y on X, where b is the regression coefficient (Statistic Toolbox)
Step 2:
 [B, I]=sortrows(b)           %I is the original column index, in this case, I=[2 5 4 1 3]
Step 3:
 X(:,2)=[]                    %Delete the column 2 of old X after sorting b
Step 4:
 [b,bint,r] = regress(y,X);   %regress y on X again
Step 5:
 [B, I]=sortrows(b)           %I is the new column index, in this case, I=[4 3 1 2]
Step 6:
 X(:,4)=[]                    % Delete the column 4 of new X
Step 7: Thus, the new matrix contains only the columns 1,3,4 of the original matrix.
How can I get original index of X after deleting? In this case, just output [1 3 4]
What I need the code to do is the following:
댓글 수: 0
채택된 답변
  KSSV
      
      
 2018년 10월 24일
        A = rand(100,50) ;   % some random data 
N = 20 ; 
C = zeros(N,1) ;
for i = 1:N
    [m,n] = size(A) ;
    b = rand(n,1) ;   % some random coefficients 
    [B,idx] = sort(b) ;
    % remove the column 
    A(:,idx(1)) = [] ;
    % save thew removed column 
    C(i) = idx(1) ;
end
% get the remained columns indics 
iwant = setdiff(1:size(A,2),C) ;
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

