Dear Marie-Edith,
the code I used for similar purposes utilizes the vecindex function
and submatrix extraction. vecindex returns row indices, therefore
the vectors have to be transposed.
----start code---
i=<7 5 4 3>';
j=(<1 2 3 4 5 6 7> |< 0.1 0.2 0.3 0.4 0.5 0.6 0.7>)';
trunc=j[vecindex(j[][0],i)][]';
print(trunc);
----end code---
---start output---
3.0000 4.0000 5.0000 7.0000
0.30000 0.40000 0.50000 0.70000
----end output---
Hope it helps,
Regards, Bernhard
> Dear OX-users,
>
> There is probably a simple solution to this, but the only one I can
> imagine is a very inefficient loop (the "real life" vectors are big):
>
> I have a vector WA=[7 5 4 3]
> and a matrix:
> WV=[1 2 3 4 5 6 7 |
> 0.1 0.2 0.3 0.4 0.5 0.6 0.7]
>
> I need to extract the elements of WV corresponding to WA:
>
> FV=[7 5 4 3 |
> 0.7 0.5 0.4 0.3]
>
> How can I do this?
>
> Thank you in advance for your help,
>
> Marie-Edith.
Bernhard Bruemmer
Institute of Agricultural Economics
Christian-Albrechts-University Kiel
Tel. (+49) 431 880 4449
Fax (+49) 431 880 4592
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|