MATLAB: Interpolation of a scatter plot

interpolation of scatter 2d plotMATLAB

Hello ;I would be most grateful if someone could give me a helping hand. i have a scatter plot where the the third variable is velocity color coded for each pair of (x,y)I woud like to interpolate this plot to have more points.below is a figure of what i have and my code as well . thanks in advance.
the interpolated points are the red piont of the second figure is having just 9 pionts. i would like to apply that to the first figure which is what i have .
plotTypes = {'mean_velocity','std_velocity','mean_pd', 'std_pd'};
for i = 1: length(plotTypes)
figure
plotType = plotTypes{i};
%subplot(1,length(plotTypes), i);
hold all ;
legendLabels = cell(1,length(plotData));
for j = 1:length(plotData)
xPlot= plotData{j}.data(:, idx.x);
yPlot= plotData{j}.data(:, idx.(plotTypes{i}));
plot(xPlot,yPlot, '-o','color',k(j,:));
legendLabels{j} = ['Y = ', num2str(plotData{j}.y)];
end
legend(legendLabels);
title(plotTypes{i}, 'Interpreter', 'none');
xlabel('x position')
ylabel(plotTypes{i}, 'Interpreter', 'none')
end
%% Generating the 3D color plot
% figure
for i = 1: length(plotTypes)
figure
legendLabels = cell(1,length(plotData));
% subplot(1,length(plotTypes), i);
hold all
for N=1:size(plotData,2)
pz =150;
plotData{1,N}.data();
x=plotData{1,N}.data(:,1);
y= plotData{1,N}.data(:,2);
%if i ==3
% z= plotData{1,N}.data(:,(i+2));
%end% Z(:,N) =plotData{1,N}.data(:,(i+2));
scatter(x,y,pz,plotData{1,N}.data(:,(i+2)),'filled')
legendLabels{N} = ['Y = ', num2str(plotData{N}.y)];
end
%%Interpolation into a gridded data
%F =scatteredInterpolant(x,y,Z);
%[xq,yq]=meshgrid(linspace(20,230,100));
%cq =F(xq,yq);
%h=pcolor(xq,yq,cq)
%legendLabels{N} = ['Y = ', num2str(plotData{N}.y)];
legend(legendLabels);
title(['3D plot of position against ',plotTypes{i}], 'Interpreter', 'none')
xlabel('X(mm)')
ylabel('Y(mm)')
H = colorbar;
ylabel(H, plotTypes{i});
end

Best Answer

Seems that scatteredInterpolant function would be better. Here is an example.
% Read data file
T = readtable('data.xlsx');
% Make interpolation function F = f(x,y)
F = scatteredInterpolant(T.xcoordinate,T.ycoordinate,T.mean_velocity);
% Make a grid points (20-by-20, for example)
[xmin,xmax] = bounds(T.xcoordinate);
[ymin,ymax] = bounds(T.ycoordinate);
[xGrid,yGrid] = meshgrid(linspace(xmin,xmax,20),linspace(ymin,ymax,20));
% Calculate interpolated value for each grid point
zGrid = F(xGrid,yGrid);
% Visualize the result
figure
scatter(xGrid(:),yGrid(:),[],zGrid(:),'filled')
colorbar
scatter.png