Is it possible to create a surface plot from scattered points?
79 views (last 30 days)
Show older comments
Good morning,
I find myself with a scatter of x and y points and would like to show them on a graph. The order of the points is random and not defined by a function. I would like to know if there is a code to turn these points into a grid so I can show my graph more clearly.
extracted from my code and current plot
position_x = Data_x
position_y = Data_y
Von_mises = Data_Von_mises
scatter(position_x, position_y, 1, Von_mises, '.')
colormap ('jet')
0 Comments
Accepted Answer
Star Strider
on 6 Jul 2022
Another approach —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1055560/Datas_xymises.txt', 'VariableNamingRule','preserve')
L = size(T1,1);
xv = linspace(min(T1{:,1}), max(T1{:,1}), fix(L/100));
yv = linspace(min(T1{:,2}), max(T1{:,2}), fix(L/100));
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(T1{:,1}, T1{:,2}, T1{:,3}, Xm, Ym)
figure
surfc(Xm, Ym, Zm, 'EdgeColor','none')
colormap(turbo)
figure
surfc(Xm, Ym, Zm, 'EdgeColor','none')
colormap(turbo)
view(0,90)
.
0 Comments
More Answers (2)
John D'Errico
on 5 Jul 2022
Edited: John D'Errico
on 5 Jul 2022
We don't have your data. But there are mltiple solutions you can use.
First is my gridfit. You can download it from the file exchange, for free use. The nice thing is gridfit will take only one line of code, but you would need to download it.
Next, you can use tools like scatteredInterpolant, then interpolating a grid of points through your data set. Compute the lattice of points using meshgrid, then just call scatteredInterpolant.
Again, since I lack your data, I can't show them in use here.
Chunru
on 5 Jul 2022
Edited: Chunru
on 5 Jul 2022
a= readmatrix("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1055560/Datas_xymises.txt")
whos
position_x = a(:, 1);
position_y = a(:, 2);
Von_mises = a(:, 3);
F = scatteredInterpolant(position_x, position_y, Von_mises);
x1 = min(position_x):0.1:max(position_x);
y1 = min(position_y):0.1:max(position_y);
[xq, yq] = meshgrid(x1, y1);
zq = F(xq, yq);
imagesc(x1, y1, zq)
colormap ('jet')
figure
surf(x1, y1, zq, 'EdgeColor', 'none')
0 Comments
See Also
Categories
Find more on Statistics and Machine Learning Toolbox 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!