Interpolation of a scatter plot
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yannick Tabot Njami
le 16 Juin 2019
Commenté : Yannick Tabot Njami
le 18 Juin 2019
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
Réponse acceptée
Akira Agata
le 18 Juin 2019
% 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
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!