フィルターのクリア

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

3 ビュー (過去 30 日間)
Savan Rangegowda
Savan Rangegowda 2017 年 6 月 20 日
回答済み: Gopichandh Danala 2017 年 6 月 20 日
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

回答 (2 件)

the cyclist
the cyclist 2017 年 6 月 20 日
編集済み: the cyclist 2017 年 6 月 20 日
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 2017 年 6 月 20 日
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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by