英文:
Create a slice plot of 3D velocity data in matlab
问题
我正在尝试在Matlab中创建一个切片图。我收到了一个错误消息,说“使用interp3时出错(第148行)。输入网格不是有效的MESHGRID。在切片(第103行)中出错vi = interp3(x,y,z,v,xi,yi,zi,method)。”按照设置方式,向量x、y、z和u将具有相同的尺寸。我不太确定如何解决这个错误,感谢任何意见。
% 定义x、y和z坐标
x = 0:1.95313:1000;
y = 0:1.95313:250;
z = 0:1.93798:250;
[y, x, z] = meshgrid(y, x, z);
u = sin(x) + sin(y) + z;
% 定义切片平面
xslice = 0;
yslice = 0;
zslice = 0;
% 创建切片图
slice(x, y, z, u, xslice, yslice, zslice);
view(3);
axis([0 1000 0 250 0 250]);
grid on;
shading interp;
xlabel('X');
ylabel('Y');
zlabel('Z');
title('三维速度矢量的切片图');
英文:
I am trying to create a slice plot in Matlab. I receive an error that says "Error using interp3 (line 148). Input grid is not a valid MESHGRID. Error in slice (line 103) vi = interp3(x,y,z,v,xi,yi,zi,method);". The way it is set up, the vectors x,y,z, and u, will share the same size. I am not entirely sure how to resolve this error and would appreciate any input.
% Define the x, y, and z coordinates
x = 0:1.95313:1000;
y = 0:1.95313:250;
z = 0:1.93798:250;
[y,x,z] = meshgrid(y,x,z);
u = sin(x) + sin(y) + z;
% Define the slice planes
xslice = 0;
yslice = 0;
zslice = 0;
% Create the slice plot
slice(x, y, z, u, xslice, yslice, zslice);
view(3);
axis([0 1000 0 250 0 250]);
grid on;
shading interp;
xlabel('X');
ylabel('Y');
zlabel('Z');
title('Slice Plot of 3D Velocity Vector');
答案1
得分: 1
The mesh variables are swapped in your code. Define the grid in the order x, y, z
and not y, x, z
, as used later:
[x, y, z] = meshgrid(x, y, z);
英文:
The mesh variables are swapped in your code. Define the grid in the order x, y, z
and not y, x, z
, as used later:
[x,y,z] = meshgrid(x,y,z);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论