help with nested indexing
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, my problem is not difficult but i am getting confused about it. So i have two vectors of indexes Nzlocs and locs
Nzlocs=[113 664 853 1236 2035];
locs=[113 202 296 403 546 606 664 812 853 909 999 1099 1189 1236 1278 1366 1460 1546 1595 1634 1722 1809 1896 1987 2035 2072 2159 2246 2333 2422 2498 2590 2674 2760 2854 2939];
and i want to find when this indexes are equal so i can finally locate my needed vector. The problem is that one vector has indexes of the other , for example the value 113 is the 1st so it will be 1 , the 664 7th so 7 etc. I wrote this code but i get an error that i exceed dimensions, note that zeropad is my custom function that performs zeropading to the needed vector so that it have same length as the other. So how can i do it, any ideas? thanks in advice.
fidx=arrayfun(@find,zeropad(Nzlocs,locs),locs ,'UniformOutput' );
採用された回答
per isakson
2015 年 9 月 3 日
編集済み: per isakson
2015 年 9 月 3 日
One way
[~,ixb] = ismember( Nzlocs, locs )
ixb =
1 7 9 14 25
and a way using arrayfun and find
fidx = arrayfun(@(x) find(x==locs), Nzlocs, 'UniformOutput', true );
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!