How to use an array as an indexing table to add search result as a new row to the querying array ?
    8 views (last 30 days)
  
       Show older comments
    
    Tamura Kentai
 on 24 Jul 2019
  
    
    
    
    
    Commented: Tamura Kentai
 on 25 Jul 2019
            Hi, :
I thank you at first.
My question is , 'How to use an array as an indexing table to add search result as a new row to the querying array ?'
For example, the Q matrix is 1000 x 1, the Idx matrix is 5 x 3, as below:
Idx =
     1     2    10
     2     3    20
     3     4    30
     4     5    40
     5     6    50
Then use Q( : ) every cell to search Idx by the logical expression, " if Idx(1 , 1 , : ) < Q(:,1) < Idx(1, 2 , :) "
,to search which row will the Q(:) be located,  then return the columns 3 of the Idx(,,3) respectively to store every it in Q by added a new column 2.
For example Q(1) = 3.5, then Idx(3, 1) = 3, Idx(3, 2) = 4, so that " Idx(3, 1) < Q(1) < Idx(3, 2)", so the Q(1) should have the returned result from Idx's column3 = 30, then store this '30', to a new column2 to Q(1,2) = '30'
Is it possible to avoid using loop, or any existing similar function to simplify it ?
Thank you very much.
Best regards.
0 Comments
Accepted Answer
  Andrei Bobrov
      
      
 on 24 Jul 2019
        
      Edited: Andrei Bobrov
      
      
 on 24 Jul 2019
  
      Q_new = [Q,Idx(discretize(Q,[Idx(:,1);Idx(end,2)]),3)];
9 Comments
More Answers (1)
See Also
Categories
				Find more on Logical in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

