Select values from 20 x 15 matrix based on a row vector 1 x 15
    8 views (last 30 days)
  
       Show older comments
    
    Parthu P
 on 7 Nov 2019
  
    
    
    
    
    Commented: Steven Lord
    
      
 on 7 Nov 2019
            I'm trying to extract values from matrix A (20 x 15) which are less than values in matrix B (1 x 15). Matrix B has 15 columns with threshold values determined from newspaper analysis. How to extract values from each column of matrix A which are less than values from corresponding columns from matrix B?
I have tried C = A < B; but I'm not able to fix matrix dimension error. 
1 Comment
  Steven Lord
    
      
 on 7 Nov 2019
				Which release of MATLAB are you using? It may be relevant particularly if you're using a release prior to release R2016b, when we introduced implicit expansion.
Accepted Answer
  JESUS DAVID ARIZA ROYETH
      
 on 7 Nov 2019
        solution: 
A(A>=B)=nan;
disp(A)
c=num2cell(A,1);
for k=1:size(c,2)
    c{k}(isnan(c{k}))=[];
    disp(['Column ' num2str(k)])
    disp(c{k})    
end
2 Comments
  JESUS DAVID ARIZA ROYETH
      
 on 7 Nov 2019
				This works well for the dimensions you indicated, could you save your workspace and attach it? look at an example:
A=rand(20,15);
B=rand(1,15);
A(A>B)=nan;
disp(A)
c=num2cell(A,1);
for k=1:size(c,2)
    c{k}(isnan(c{k}))=[];
    disp(['Column ' num2str(k)])
    disp(c{k})    
end
More Answers (1)
  kondepati sudhir kumar
 on 7 Nov 2019
        if use the C = A <B; you wil get the logic matrix. If you have dimensional error then it is better give the c = zeros (size (a));
i hope it works.
0 Comments
See Also
Categories
				Find more on Christmas / Winter in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!