How to use an array as an indexing table to add search result as a new row to the querying array ?
1 次查看(过去 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!