Sorting large vector onto 2D grid
5 次查看(过去 30 天)
显示 更早的评论
Hi all,
I would like to sort a vector of measurements onto a 2D grid, by the corresponding latitude and longitude.
I start with a vector of measurements (meas), a vector which lists which row the value corresponds to (row), and a vector which lists which column the value corresponds to (col). 'row' and 'col' are calculated from the latitude and longitude of the raw file data.
If I am using a (360,720) grid, I could do the following:
for i = 1:360
for j = 1:720
index = find(row== i & col == j);
values = meas(index) *NB
end
end
*NB I realise this line would give an error - it is simplified slightly for the sake of this post. Essentially what I do in my actual code here is store the values as a 3D grid (row, col, #measurements).
This is really quite slow. I have been playing with alternatives, but can't quite get my head around how to do this faster. I have been sorting by 'row' and 'col' as in the accepted answer to this question....
This got me close, but I couldn't quite adapt this method for use with two sorts (row and col).
Anyone got any ideas as to how to do this, without using find in a loop. With (360 x 720) grid cells, that's a lot of calls to 'find'!
Thanks,
Dom
0 个评论
采纳的回答
Thorsten
2013-1-24
sz = [360 720];
ind_list = sub2ind(sz, row, col);
for i = 1:360
for j = 1:720
index = 360*(j - 1) + i;
values{i, j} = meas(find(ind_list == index));
end
end
更多回答(1 个)
Thorsten
2013-1-24
sz = [360 720];
ind = sub2ind(sz, row, col);
values = zeros(sz);
values(ind) = meas;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!