Search rows of a matrix on another and read data respectively.
2 ビュー (過去 30 日間)
古いコメントを表示
Hi
I have a data set file with headers as 'LatDegree, LongDegree, LatUTM, LongUTM, Height'. I have a calculated matrix consists of just two headers as 'LatDegree, LongDegree', too. I attached a sample of these files.
I want to search each row of calculated matrix in data set and add other corresponded items to calculated matrix based on my data set.
How I should do that? I have to use vectorized code to improve the speed.
Thanks
Mani
0 件のコメント
回答 (1 件)
dpb
2014 年 9 月 27 日
編集済み: dpb
2014 年 9 月 28 日
[~,ia]=intersect(A(:,1:2),B,'rows','stable'); % locations
B=[B A(ia,3:end)];
ADDENDUM
OK, I didn't look at the actual values; presumed there wouldn't be duplicates. To handle repeats in the lookup set, use ismember instead...
[~,ia]=ismember(B,A(:,[1:2]),'rows');
B=A(ia,:);
I often wish there were some way to write syntax to get the alternate return value w/o the temporary indexing vector...
2 件のコメント
dpb
2014 年 9 月 28 日
編集済み: dpb
2014 年 9 月 28 日
See ADDENDUM in Answer section -- as noted, didn't expect there to be repeats.
But, would have thought that seeing ismember would have caused to look at the doc to see if it could be made to handle the repeated fields and then the "See Also" cast of characters thereat would have led you to...
Just a side note on how to think about and approach solving these problems in Matlab on your own rather than waiting around until somebody gets back here...
参考
カテゴリ
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!