Is it possible to create a surface plot from scattered points?

79 次查看(过去 30 天)
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')

采纳的回答

Star Strider
Star Strider 2022-7-6
Another approach —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1055560/Datas_xymises.txt', 'VariableNamingRule','preserve')
T1 = 208150×3 table
Var1 Var2 Var3 _______ ____ ______ -40.164 -27 261.1 -24.593 -27 261.1 119.77 -27 285.94 134.98 -27 285.94 -165.02 -27 287.87 -165.02 -27 278.01 -149.41 -27 278.01 150.19 -27 273.58 165.4 -27 273.58 134.98 -27 291.26 -180 -27 262.09 165.4 -27 262.09 -24.593 -27 269.85 -55.771 -27 337.77 25.772 -27 243.73 42.001 -27 243.73
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)
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Zm = 2081×2081
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 195.4842 247.3430 299.2017 312.5283 285.1126 257.6968 283.4510 346.6657 409.8805 358.4613 268.8926 179.3239 257.9251 365.9919 474.0587 521.2880 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 203.1074 254.9662 290.6851 263.2694 235.8537 263.3375 326.5522 379.9301 290.3614 200.7927 203.4293 311.4961 419.5629 472.0872 516.2165 543.5631 536.4212 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 158.8718 210.7306 262.5894 241.4262 214.0105 243.2240 306.4388 311.8302 222.2615 148.9335 257.0003 365.0672 422.8865 467.0157 483.4836 476.3417 450.2047 364.9652 279.7257 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 166.4950 218.3538 219.5830 192.1673 223.1105 286.3253 243.7303 154.1615 202.5045 310.5714 373.6857 417.8150 423.4040 416.2622 350.0039 264.7643 214.7590 175.7453 143.8064 113.5180 NaN NaN NaN NaN NaN NaN NaN NaN 122.2594 174.1182 197.7398 170.3241 202.9970 265.1991 175.6303 148.0088 256.0756 324.4849 368.6142 363.3245 335.0425 249.8030 191.2590 152.2453 121.2687 98.8680 103.1852 104.4804 103.1462 101.8120 NaN NaN NaN NaN NaN NaN NaN 129.8826 175.8967 148.4809 182.8836 197.0991 107.5304 201.5798 275.2841 310.3868 303.2450 234.8417 167.7590 129.0194 98.7309 90.5820 93.4969 92.1627 90.8286 89.4944 88.1602 86.8261 85.4919 85.7871 NaN NaN NaN NaN NaN NaN 137.5058 126.6377 162.7701 128.9992 147.0840 226.0834 250.3073 219.8804 144.2590 106.4816 77.9788 82.2959 81.1793 79.8451 78.5110 77.1768 75.8426 76.4933 77.6544 78.8155 79.9765 81.1376 82.2987 83.4598 NaN NaN NaN NaN 93.2703 104.7946 142.6566 92.5883 176.8826 190.2278 120.7590 83.9438 69.6927 70.1958 68.8617 67.5275 66.1933 67.1996 68.3606 69.5217 70.6828 71.8438 73.0049 74.1660 75.3271 76.4881 77.6492 78.8103 79.9713 81.1324 NaN NaN NaN 82.9514 82.3681 127.6818 104.7182 61.4061 59.2124 57.8782 56.7447 57.9058 59.0668 60.2279 61.3890 62.5501 63.7111 64.8722 66.0333 67.1943 68.3554 69.5165 70.6776 71.8386 72.9997 74.1608 75.3218 76.4829 77.6440 78.8051 NaN 56.6579 77.2105 48.2289 47.4509 48.6120 49.7731 50.9341 52.0952 53.2563 54.4173 55.5784 56.7395 57.9006 59.0616 60.2227 61.3838 62.5448 63.7059 64.8670 66.0281 67.1891 68.3502 69.5113 70.6723 71.8334 72.9945 74.1556 75.3166 76.4777
figure
surfc(Xm, Ym, Zm, 'EdgeColor','none')
colormap(turbo)
figure
surfc(Xm, Ym, Zm, 'EdgeColor','none')
colormap(turbo)
view(0,90)
.

更多回答(2 个)

John D'Errico
John D'Errico 2022-7-5
编辑:John D'Errico 2022-7-5
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.
  1 个评论
Reto Kurz
Reto Kurz 2022-7-5
Thank you very much for your disposnibility
I will leave you attached the data I have available in order x y and Von-Mises.

请先登录,再进行评论。


Chunru
Chunru 2022-7-5
编辑:Chunru 2022-7-5
a= readmatrix("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1055560/Datas_xymises.txt")
a = 208150×3
-40.1642 -27.0000 261.1000 -24.5926 -27.0000 261.1000 119.7732 -27.0000 285.9400 134.9791 -27.0000 285.9400 -165.0159 -27.0000 287.8700 -165.0159 -27.0000 278.0100 -149.4072 -27.0000 278.0100 150.1904 -27.0000 273.5800 165.4005 -27.0000 273.5800 134.9791 -27.0000 291.2600
whos
Name Size Bytes Class Attributes a 208150x3 4995600 double cmdout 1x33 66 char
position_x = a(:, 1);
position_y = a(:, 2);
Von_mises = a(:, 3);
F = scatteredInterpolant(position_x, position_y, Von_mises);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
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')

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by