To find the value in a vector for the corresponding indices from another vector
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (2)
the cyclist
il 20 Giu 2017
Modificato: the cyclist
il 20 Giu 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)
0 Commenti
Gopichandh Danala
il 20 Giu 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!