Sorting large vector onto 2D grid

5 visualizaciones (últimos 30 días)
Initial Conditions
Initial Conditions el 24 de En. de 2013
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

Respuesta aceptada

Thorsten
Thorsten el 24 de En. de 2013
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 comentario
Initial Conditions
Initial Conditions el 24 de En. de 2013
Thorsten,
Will try this code now - but looks good to me. Many thanks.

Iniciar sesión para comentar.

Más respuestas (1)

Thorsten
Thorsten el 24 de En. de 2013
sz = [360 720];
ind = sub2ind(sz, row, col);
values = zeros(sz);
values(ind) = meas;
  2 comentarios
Initial Conditions
Initial Conditions el 24 de En. de 2013
Thorsten,
Thanks for the quick reply. This looks promising. However the end result is a 360 * 720 grid where each cell has one measurement. I should have mentioned each cell can have (and does have) more than one value usually around 10. Could you adapt for this? Is your above code just finding the first instance for each cell?
Many thanks,
Dom
Initial Conditions
Initial Conditions el 24 de En. de 2013
To be clearer, this is satellite swath data, so cells can have between 0 and approx 50 measurements per set of 'meas'. I would like to store each measurement at a grid cell - sort of like a stacked 2D array.
Dom

Iniciar sesión para comentar.

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by