How to use an array as an indexing table to add search result as a new row to the querying array ?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tamura Kentai
le 24 Juil 2019
Commenté : Tamura Kentai
le 25 Juil 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 commentaires
Réponse acceptée
Andrei Bobrov
le 24 Juil 2019
Modifié(e) : Andrei Bobrov
le 24 Juil 2019
Q_new = [Q,Idx(discretize(Q,[Idx(:,1);Idx(end,2)]),3)];
9 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!