How to use an array as an indexing table to add search result as a new row to the querying array ?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tamura Kentai
el 24 de Jul. de 2019
Comentada: Tamura Kentai
el 25 de Jul. de 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 comentarios
Respuesta aceptada
Andrei Bobrov
el 24 de Jul. de 2019
Editada: Andrei Bobrov
el 24 de Jul. de 2019
Q_new = [Q,Idx(discretize(Q,[Idx(:,1);Idx(end,2)]),3)];
9 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!