how to grid data

Hi;
I have the attached data:
Col1: time,
Col2: lat,
Col3: long,
Col4: obs
I need to grid these data (2.5 lat x 5 long).
My trial:
clear all;
load('data.mat')
x=data(:,3);
LON=-50:5:50;
y= data (:,2);
LAT=-50:2.5:50;
z= data(:,4);
[X,Y] = meshgrid(LAT, LON);
Z = griddata(x,y,z,X,Y,'cubic');
Warning: Duplicate x-y data points detected: using average values for duplicate points.
figure
contourf(X,Y,Z);
grid on
ylim([-20 40])
xlim([-20 50])
shading('interp')
view(0,90)
colormap('jet')
colorbar
xlabel('LONG')
ylabel('LAT')

5 Commenti

ahmad Saad
ahmad Saad il 17 Ott 2023
Is that correct ??
or it needs further improvment
load('data.mat')
x = data(:,3);
y = data(:,2);
z = data(:,4);
xy = [x, y];
[C, ~, IC] = unique(xy, 'rows');
counts = accumarray(IC(:), 1);
groups_with_dups = find(counts ~= 1);
for gidx = groups_with_dups(:).'
fprintf('\npoint [%g, %g] occurs at multiple data rows:\n', C(gidx, :));
for drow = reshape(find(IC == gidx), 1, []);
fprintf('row %d, z = %g\n', drow, z(drow));
end
end
point [-144.51, -6.73] occurs at multiple data rows:
row 47280, z = 4.1113 row 47283, z = 4.1107
point [-75.78, -1.99] occurs at multiple data rows:
row 17301, z = 8.6068 row 34415, z = 5.1247
point [-61.66, -9.88] occurs at multiple data rows:
row 10323, z = 7.0779 row 15532, z = 10.0557
point [-55.54, -6.1] occurs at multiple data rows:
row 31862, z = 8.8563 row 31863, z = 8.8596
point [-33.82, -4.96] occurs at multiple data rows:
row 21227, z = 18.4858 row 21228, z = 18.4862
point [-11.76, 0.47] occurs at multiple data rows:
row 27779, z = 1.8626 row 27782, z = 1.863
point [133.26, -9.25] occurs at multiple data rows:
row 39336, z = 5.4963 row 46912, z = 11.4154
point [138.27, -1.99] occurs at multiple data rows:
row 14161, z = 6.6767 row 32244, z = 3.7447
point [148.27, 27.37] occurs at multiple data rows:
row 23840, z = 11.7684 row 53067, z = 3.1711
point [150.92, -6.33] occurs at multiple data rows:
row 1010, z = 4.9438 row 24012, z = 2.754
ahmad Saad
ahmad Saad il 17 Ott 2023
@Walter Roberson i need to grid the data then plot it
Walter Roberson
Walter Roberson il 17 Ott 2023
And you already did that.
However, you have duplicate points with different Z values. How do you want to handle those points? griddata() handles the situation by taking mean() of the z at the locations with duplicates.
ahmad Saad
ahmad Saad il 17 Ott 2023
Actully, i am not sure if my code is correct or not

Accedi per commentare.

Risposte (0)

Richiesto:

il 17 Ott 2023

Commentato:

il 17 Ott 2023

Community Treasure Hunt

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

Start Hunting!

Translated by