Need Help with Streamline Function in MATLAB

조회 수: 35 (최근 30일)
Chijing
Chijing 2024년 1월 15일
댓글: Chijing 2024년 2월 7일
Hi, I am using quiver and streamline functions and here is my code:
figure;
startX =xavgsym(1,:)'
startY=yavgsym(1,:)';
quiver(xavgsym,yavgsym,uavgsym(:,:,2),vavgsym(:,:,2))
hold on
streamline(xavgsym,yavgsym,uavgsym(:,:,2),vavgsym(:,:,2),startX,startY)
hold off
xlim([-20 20])
ylim([-5 25])
The 'quiver' function works fine and I got a nice velocity vector plot. However, I'm not getting any output for the 'streamline' function
I've tried a couple of things to resolve the issue, but none of them worked:
  1. using 'stream2': verts=stream2(xavgsym,yavgsym,uavgsym(:,:,2),vavgsym(:,:,2),startX,startY);
  2. defined different 'startX' and 'startY' using meshgrid: [startX,startY] = meshgrid(10,0:10:25);
I also checked there is no NaN's in u and v, and 'startX' and 'startY' values are in the range of my x, y data
I have attached the data. Any assistance or guidance on this matter would be greatly appreciated. Thank you in advance!

답변 (1개)

Shubh
Shubh 2024년 1월 18일
Hi Chijing,
It seems the issue with the 'streamline' function not producing output in MATLAB could be related to how the data is structured or how the streamline function is being called. Given that your 'quiver' plot works correctly, but 'streamline' does not, let's review and adjust your MATLAB code.
First, ensure that the xavgsym and 'yavgsym' matrices form a regular grid. MATLAB's 'streamline' function requires a grid of starting points, which might not align with your data if it's irregularly spaced or not sorted. Here's how you can approach it:
  1. Check Grid Regularity: Ensure 'xavgsym' and 'yavgsym' are regularly spaced. If they aren't, you might need to interpolate your data onto a regular grid.
  2. Interpolate Data if Necessary: If your grid is irregular, use MATLAB's 'interp2' function to interpolate 'uavgsym' and 'vavgsym' onto a regular grid.
  3. Adjust Start Points: The start points for the streamlines (startX, startY) should be within the bounds of your grid. Make sure they are not outside the range of 'xavgsym' and 'yavgsym'.
Here's a revised version of your code with these considerations:
% Assuming xavgsym, yavgsym, uavgsym, and vavgsym are already loaded
% Check if the grid is regular
if ~isequal(size(xavgsym), size(yavgsym))
error('xavgsym and yavgsym must be the same size');
end
% Select the appropriate slice for u and v
u_slice = uavgsym(:,:,2);
v_slice = vavgsym(:,:,2);
% Create a figure
figure;
% Plot the quiver
quiver(xavgsym, yavgsym, u_slice, v_slice);
hold on;
% Set start points for streamline - adjust as needed
startX = xavgsym(1,:)';
startY = yavgsym(1,:)';
% Check if startX and startY are within the range
if any(startX < min(xavgsym(:))) || any(startX > max(xavgsym(:))) || ...
any(startY < min(yavgsym(:))) || any(startY > max(yavgsym(:)))
error('Start points are outside the grid range');
end
% Generate streamlines
streamline(xavgsym, yavgsym, u_slice, v_slice, startX, startY);
% Set axes limits
xlim([-20 20]);
ylim([-5 25]);
hold off;
This code addresses potential issues with grid regularity and start points. If the 'streamline' function still doesn't produce output, you might want to further investigate the characteristics of your velocity field data ('uavgsym' and 'vavgsym'). Ensure that the velocities are not too small or too uniform, as this might also cause streamlines to be less visible or not appear at all.
Hope this helps!
  댓글 수: 1
Chijing
Chijing 2024년 2월 7일
Hi Shubh,
Thanks for your reply. I've tried the code you provided by couldn't get this problem solved.

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

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by