how to grid data
Show older comments
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');
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 Comments
ahmad Saad
on 17 Oct 2023
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
ahmad Saad
on 17 Oct 2023
Walter Roberson
on 17 Oct 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
on 17 Oct 2023
Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!