# how can I find points in specific cell without 'for' loop?

1 visualizzazione (ultimi 30 giorni)
Mina Mino il 23 Lug 2023
Risposto: Walter Roberson il 23 Lug 2023
I have gridded a region with regular cells (about 5000 cells). the latitude and longitude of the center of the cells are known. I have milions of measurements (latitude and longigture are also known) from a satellite over the region and I want to find measurements in each cell and average the value of the observations over each cell. How can I do this without using "for" loop? Thanks in advance for your help and consideration.
Best,
Mina
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

Star Strider il 23 Lug 2023
Without knowing the details of the cell array, the cellfun function is likely the moist appropriate option. It avoids explicit loops, however it loops internally, since there is no way around that. (I assume that ‘cell’ refers to cell arrays.)
It would help to have a representative sample of your data, or something that accurately simulates its structure, and a description of what you want to do with it.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Walter Roberson il 23 Lug 2023
When dealing with gridded map coordinates, the grid will either be rectangular in degrees or else rectangular in some physical distances. If it is rectangular in degree, then the angular distance covered by each cell is the same, but the physical distance might not be the same. For example, the cells might be consistently 1/10th degree longitude apart everywhere, but if the top is at (say) 60 degrees north and the bottom is at the equator then the physical distances between the east and west edges might be fairly different between the top and bottom.
If you have consistent angles, then typically it becomes easy to figure out which cell a particular sensor reading falls in --
long_bin_number = floor((sensor_long - west_edge_long) / long_width_of_bins) + 1;
and likewise for latitude. Or use discretize . This technique works as long as the bin calculation for one direction never depends upon the current coordinate in the other direction.
If, though, what you have is a grid over physical distances (for example, the bins are 750 meters tall by 500 meters wide) but the sensors locations are in terms of lat and long, then often the easiest way to move between lag and long and bin numbers is to use histcounts2 and use the output bin numbers.
Once you have latitude bin numbers and longitude bin numbers for each sensor reading, you can proceed in a variety of ways. The older (and still quite efficient) way is to use accumarray which works very well but can be difficult to understand the first several times you use it. These days functions such as groupsummary might be considered as an alternative.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Logical in Help Center e File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by