How to use an array as an indexing table to add search result as a new row to the querying array ?
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Andrei Bobrov
2019 年 7 月 24 日
編集済み: Andrei Bobrov
2019 年 7 月 24 日
Q_new = [Q,Idx(discretize(Q,[Idx(:,1);Idx(end,2)]),3)];
9 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!