MATLAB Answers

Averaging z values for xy gridded data

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

  댓글 수: 0

댓글을 달려면 로그인하십시오.

답변(2개)

Shounak Shastri
Shounak Shastri 24 Feb 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!!

  댓글 수: 0

댓글을 달려면 로그인하십시오.


KSSV
KSSV 24 Feb 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

  댓글 수: 0

댓글을 달려면 로그인하십시오.

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by