Hello,
I have X,Y,Z,U,V,W 3D arrays of the size 101x201x4. I plotted slice and streamslie in the x-z plane along y = -3 as shown in the attached figure (red line). The code is:
[X,Y,Z] = meshgrid(-4:0.05:6,-5:0.05:0,1:4);
% Plot streamlines for the given cross-section
ssh = streamslice(X,Y,Z,U,V,W,[],-3,[]);
set(ssh,'Color',[0 0 0],'LineWidth',2)
hold on
view(0,0)
% Plot volumetirc slice
Vel = sqrt(U.^2+V.^2+W.^2)
sh = slice(X,Y,Z,Vel,[],-3,[]);
colormap jet
set(sh,'EdgeColor','none',...
'FaceColor','interp',...
'FaceAlpha','interp');
alpha('color');
% c = colorbar('Location','eastoutside');
view(0,0)
zlim([0.5,4]); zl = zlim; zticks([1,2,3,4])
How can I plot the horizontal vs. z direction along the green line in the attached figure? That is, how to specify planes that are not at constant x,y or z?
Attahed is also a plot of what I would like in the diagonal direction, but I made it at y = -3 (red line in Slice.png)
Thank you,
djr

 채택된 답변

darova
darova 2020년 5월 2일

1 개 추천

Try this simple example
[x,y,z,v] = flow;
[Z,Y] = meshgrid(-3:0.5:3);
X = 3+(Z.^2+Y.^2)/5;
slice(x,y,z,v,X,Y,Z)
hold on
slice(x,y,z,v,[1 9],2,-2)
hold off
axis vis3d equal

댓글 수: 7

djr
djr 2020년 5월 2일
편집: djr 2020년 5월 2일
I would apriciate if you test the same code for streamslice on your computer and let me know how it goes. Because it crashes on mine.
djr
djr 2020년 5월 2일
Thank you Darova. It seems the streamslice does not work with an arbitrary plane.
I appricate your help.
Regards,
djr
darova
darova 2020년 5월 2일
try this
  • calculate direction vectors for surface you want streamline
  • use stream2 to generate streamline for plane
  • use interp2 to calculate 3d coordinate
djr
djr 2020년 5월 2일
That looks awesome! I will try this one for sure.
Thanks!
Ameer Hamza
Ameer Hamza 2020년 5월 2일
I suggest darova to add this comment as a separate answer so that djr can accept that. This code uses clever tricks and correctly solves the issue posed in the question.
djr
djr 2020년 5월 3일
I agree, I would be happy to do that. Should I post a new question separately or we can somehow do it here?
Ameer Hamza
Ameer Hamza 2020년 5월 3일
You can do it here. First unaccept my answer and then accept darova’s answer. Even accepting darova’s current answer will make it easy for anyone coming to this page to find a solution. Alternatively, if darova posted a new answer later, you can accept that too.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 5월 2일
편집: Ameer Hamza 2020년 5월 2일

0 개 추천

See this example, on how to create an arbitrary surface for the slice function: https://www.mathworks.com/help/releases/R2020a/matlab/ref/slice.html#mw_e9ea56fc-b860-4fbe-99d5-6c3e4725132f
You will need to do something like this. Suppose the equation of the green line is z=2*x (assuming x-axis is the horizontal axis)
x_range = -1:0.1:1;
y_range = -5:0.1:1;
[X_grid, Y_frid] = meshgrid(x_range, y_range);
Z = 2*x;
slice(X,Y,Z,V,X_grid,y_grid,Z)

댓글 수: 3

djr
djr 2020년 5월 2일
편집: djr 2020년 5월 2일
I also found this example (http://www.ece.northwestern.edu/local-apps/matlabhelp/techdoc/ref/slice.html), but I can't make it work for my data. It uses
surface
and
rotate
but there are some problems. When I pass (xd,yd,zd) to streamslice (not slice), then my Matlab (2018b) freezes. For some reason it takes way more time to do streamslice than slice.
It seems from the documentation of streamslice function that it might not be possible to create it along a specific plane. It just creates it parallel to the coordinate planes.
Try this simple example. I used a small grid to illsutrate the idea.
load wind
[xg, yg] = meshgrid(80:5:90, 20:2:25);
zg = 2*xg+yg;
streamslice(x,y,z,u,v,w,xg,yg,zg)
view(3)
djr
djr 2020년 5월 2일
Thanks a lot! Indeed it seems that the streamslice is not capable of handling a specific plane. That's a pity.
Cheers,
djr

댓글을 달려면 로그인하십시오.

카테고리

질문:

djr
2020년 5월 2일

댓글:

2020년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by