To find the value in a vector for the corresponding indices from another vector

3 visualizaciones (últimos 30 días)
Hi Everyone,
I have small issue in finding the values from a vector for the corresponding indices from another vector. for ex:
If I have a vector:
aa = [0.023 0.987 0.112 0.666 0.2734, .... , 0.6667]; % say dimension of 1x1000
and
bb = [34 12 67 87 76 83 11 97 23 112 298]; % say dimension of 1x50 (which are the index values for which I want the corrsponding values from aa.
I don't want to use a for loop!!
I did something wrong like
cc = aa(bb(1:end));
error message: Index exceeds matrix dimensions. %(because it does not make sense)
Can anyone suggest me any solution! It would of great help.
Thanks in advance!
Cheers, Savan

Respuestas (2)

the cyclist
the cyclist el 20 de Jun. de 2017
Editada: the cyclist el 20 de Jun. de 2017
Your largest value of bb must be longer than the length of aa.
You can check this by comparing
max(bb)
with
length(aa)

Gopichandh Danala
Gopichandh Danala el 20 de Jun. de 2017
There is nothing wrong in your code, maybe some of the indices in bb are higher than length of aa, which is giving that error.
Just verify
logical(max(bb) < length(aa))
if its true (1), there is no problem , if its false (0) some index in bb is higher than length of aa and causing the error

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!

Translated by