![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/721144/image.jpeg)
Interpolating [X Y Z V] values on cylinder surface
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ionesco
el 25 de Ag. de 2021
Comentada: Simson Hutagalung
el 5 de Jul. de 2022
I have four 1D arrays: x,y,z and v, representing (x,y,z) coordinates on a cylinder and v, the value (temperature) measured in that respective (x,y,z) point.
What I would like is to show the temperature distribution on the surface of the cylinder by interpolating these values. Something like this: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/721064/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/721064/image.jpeg)
What I have managed is to scatter those points on the surface of the cylinder:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/721059/image.png)
For the interpolation, I tried to use meshgrid and griddata, but I can't make it work.
function plot3D(x,y,z,v,m)
ddx=(2*pi*max(x))/m;
ddy=(2*pi*max(x))/m;
ddz=(max(z)-min(z))/m;
dx = min(x):ddx:max(x);
dy = min(y):ddy:max(y);
dz = min(z):ddy:max(z);
Tmin = min(v);Tmax=max(v);
[xqX,yqX,zqX] = meshgrid(dx,dy,dz);
vqX = griddata(x,y,z,v,xqX,yqX,zqX);
surf(xqX,yqX,zqX,vqX),hold on,
caxis([Tmin Tmax]);colormap('jet');shading interp;colorbar;
end
Any ideas if it is possible?
0 comentarios
Respuesta aceptada
Wan Ji
el 25 de Ag. de 2021
Editada: Wan Ji
el 25 de Ag. de 2021
Actually, scatteredInterpolant function is easy to implement what you think.
function plot3D(x,y,z,v,m)
% scatter3(x,y,z);
Tmin = min(v); Tmax = max(v);
radius = mean(sqrt(x.^2+y.^2)); % use mean radius as radius
theta = linspace(0, 2*pi,m+1); % divide theta to m segments
minZ = min(z); maxZ = max(z);
Z = linspace(minZ, maxZ, m+1); % divide z to m segments
[Z, T] = meshgrid(Z, theta); % create meshgrid with theta and z
X = radius.*cos(T); % calculate X and Y for mesh
Y = radius.*sin(T);
F = scatteredInterpolant(x,y,z,v,'linear'); % create interp handle
V = zeros(size(X));
V(:) = F(X(:),Y(:),Z(:)); % interp the value
Vave = 0.5*(V(end,:)+V(1,:)); % fix the minor flaw (average the beginnig and the end of corresponding theta)
V(end,:) = Vave; % fix the minor flaw
V(1,:) = Vave; % fix the minor flaw
surf(X,Y,Z,V,'edgecolor','none')
caxis([Tmin Tmax]);colormap('jet');shading interp;colorbar;
Now use this function to produce figure
load('xyzvm_cylinder.mat')
plot3D(x,y,z,v,40)
The result shows as following
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/721144/image.jpeg)
4 comentarios
Simson Hutagalung
el 5 de Jul. de 2022
How if using excel file? Like the coordinates, nodes, and the value of stress?
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!