Deleting some columns of matrix and obtain the original column index.
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Wan-Yi Chiu
 el 24 de Oct. de 2018
  
    
    
    
    
    Editada: Wan-Yi Chiu
 el 24 de Oct. de 2018
            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 comentarios
Respuesta aceptada
  KSSV
      
      
 el 24 de Oct. de 2018
        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 comentarios
Más respuestas (1)
Ver también
Categorías
				Más información sobre Multidimensional Arrays en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

