plot a surface from a three variable table
古いコメントを表示
I have a 3 column table and need help with applying meshgrid to the first two columns and reshaping the third column into a matrix to use with surf(x,y,z). I tried something like:
[X,Y]=meshgrid(table.Temperature,table.StrainRate) but got an error that it is too large of a request
Error using repmat
Requested 202005x202005 (304.0GB) array exceeds maximum array size preference
(31.6GB). This might cause MATLAB to become unresponsive.
I believe that once I get the meshgrid issue sorted I can then turn the Z column 'Stress' into a matrix using
reshape(z, size(X))
Is this correct?
Thanks for any help!
採用された回答
その他の回答 (1 件)
Walter Roberson
2025 年 5 月 8 日
If not the below code, then use meshgrid instead of ndgrid
This code takes a long time to execute !! The internal triangulation that is done by scatteredInterpolant takes a long time on the 197400 data points that remain after removing the missing entries.
load('table.mat');
t7 = rmmissing(t6);
F = scatteredInterpolant(t7.Temperature, t7.StrainRate, t7.Stress);
[tmin, tmax] = bounds(t7.Temperature);
[srmin, srmax] = bounds(t7.StrainRate);
N = 100;
[tG, srG] = ndgrid(linspace(tmin, tmax, N), linspace(srmin, srmax, N+1));
stG = F(tG, srG);
surf(tG, srG, stG, 'edgecolor', 'none');
4 件のコメント
Corey
2025 年 5 月 8 日
Walter Roberson
2025 年 5 月 8 日
This is the plot of the above. I think it needs a finer grain than N = 100
Notice the large flat area. Surface plots seldom adapt themselves to the shape of the data.

Walter Roberson
2025 年 5 月 8 日
The reason that I made the srG one unit longer than the tG, is a safety check for the surf(). If you give the parameters in the wrong order to surf, then if the parameters are all square matrices, then surf() will end up plotting them the wrong way around. If you make the parameters non-square then if you give the parameters in the wrong order to surf() then surf will complain about the array sizes not properly matching.
It happens that I did give the parameters in the correct order and used the correct ndgrid() instead of meshgrid(), so everything plotted correctly in this code -- but I could easily have gotten it wrong, in which case surf() would have given me an error message about the array size not matching instead of silently plotting the data incorrectly.
Walter Roberson
2025 年 5 月 8 日
The stG = F(tG, srG); took a pretty long time. Somewhere between half an hour and an hour on my machine.
I suspect that the bulk of the time is in performing the triangulation, so I don't think reducing N to (say) 50 would speed it up all that much.
カテゴリ
ヘルプ センター および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


