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

6 Ansichten (letzte 30 Tage)
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

Antworten (2)

the cyclist
the cyclist am 20 Jun. 2017
Bearbeitet: the cyclist am 20 Jun. 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 am 20 Jun. 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

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by