Averaging z values for xy gridded data

조회 수: 1 (최근 30일)
Ara Cate
Ara Cate 2020년 2월 24일
답변: KSSV 2020년 2월 24일
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.

답변 (2개)

Shounak Shastri
Shounak Shastri 2020년 2월 24일
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 2020년 2월 24일
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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by