plot a surface from a three variable table

4 visualizaciones (últimos 30 días)
Corey
Corey el 8 de Mayo de 2025
Comentada: Walter Roberson el 8 de Mayo de 2025
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 comentario
Corey
Corey el 8 de Mayo de 2025
For more context, this is a scatter3 plot of the data in the attached table, what I would like to do is make a surface plot of the maximum stress values

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 8 de Mayo de 2025
Load and plot the data:
T = load('table.mat','t6').t6;
figure
plot3(T.(1),T.(2),T.(3),'.')
set(gca,'XScale','log','YScale','log','YDir','reverse')
grid on
axis tight
To make the requested surface, you can try something along these lines:
T = T(all(isfinite(T{:,:}),2),:)
T = 197400x3 table
Temperature StrainRate Stress ___________ __________ ______ 700 2.2903e-07 71.38 700 2.2815e-07 71.311 700 2.2738e-07 71.25 700 2.2644e-07 71.177 700 2.253e-07 71.086 700 2.2388e-07 70.97 700 2.2245e-07 70.853 700 2.2102e-07 70.737 700 2.196e-07 70.621 700 2.1817e-07 70.505 700 2.1675e-07 70.389 700 2.1532e-07 70.272 700 2.139e-07 70.156 700 2.1247e-07 70.04 700 2.1183e-07 69.987 700 2.1179e-07 69.982
[x,~,xidx] = unique(T.(1));
NX = numel(x);
NY = 100;
[yidx,yedge] = discretize(log(T.(2)),NY);
y = (yedge(1:end-1)+yedge(2:end))/2;
y(~ismember(1:NY,unique(yidx))) = [];
y = exp(y);
z = groupsummary(T.(3),[xidx,yidx],'max','IncludeEmptyGroups',true);
z = reshape(z,[],NX);
figure
surf(x,y,z)
set(gca,'XScale','log','YScale','log','YDir','reverse')
grid on
axis tight

Más respuestas (1)

Walter Roberson
Walter Roberson el 8 de Mayo de 2025
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 comentarios
Walter Roberson
Walter Roberson el 8 de Mayo de 2025
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
Walter Roberson el 8 de Mayo de 2025
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by