Averaging z values for xy gridded data

2 visualizaciones (últimos 30 días)
Ara Cate
Ara Cate el 24 de Feb. de 2020
Respondida: KSSV el 24 de Feb. de 2020
I have a dataset of lat lon areas and corresponding values. This is a small sample:
maxlat minlat minlon maxlon temp
60.0000 50.0000 170.0000 180.0000 -16.1680
60.0000 50.0000 170.0000 180.0000 -8.6020
70.0000 60.0000 170.0000 180.0000 -52.5874
70.0000 60.0000 170.0000 180.0000 -54.0840
70.0000 60.0000 170.0000 180.0000 -53.5014
0 -10.0000 170.0000 180.0000 19.6848
0 -10.0000 170.0000 180.0000 22.4549
10.0000 0 170.0000 180.0000 -56.9327
10.0000 0 170.0000 180.0000 -65.2633
I don't know how to average the temp values for each grid area where values of lat and lon are equal.

Respuestas (2)

Shounak Shastri
Shounak Shastri el 24 de Feb. de 2020
Hello Ara,
So the brute force implementation would be to run a search through your data and check the lat and lon values. If they are equal, then copy the temp values in a separate array. Once you have gone through the completre data, you can use mean() to find the average. This is a lenghty process though and might take some time to complete.
An easier way to do this would be to use find() to get the indices of all the values of maxlat which are same, then check if those rows are equal.
for example,
k = find(maxlat == maxlat(1)); %Generate a vector of rows with same values of maxlat
%say k = [1, 2]
%the name of your table is "table"
isequal (table(k(1), :), table(k(2), :))% Check if all the coloums are equal
if the answer is true, then average, otherwise skip.
Good Luck!!

KSSV
KSSV el 24 de Feb. de 2020
A = [60.0000 50.0000 170.0000 180.0000 -16.1680
60.0000 50.0000 170.0000 180.0000 -8.6020
70.0000 60.0000 170.0000 180.0000 -52.5874
70.0000 60.0000 170.0000 180.0000 -54.0840
70.0000 60.0000 170.0000 180.0000 -53.5014
0 -10.0000 170.0000 180.0000 19.6848
0 -10.0000 170.0000 180.0000 22.4549
10.0000 0 170.0000 180.0000 -56.9327
10.0000 0 170.0000 180.0000 -65.2633];
temp = A(:,end) ;
lat = A(:,1) ;
[c,ia,ib] = unique(lat) ;
temp_avg = zeros(length(c),1) ;
for i = 1:length(c)
temp_avg(i) = mean(temp(ib==i)) ;
end

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by