Hello,
I have a problem with plotting the 2D streamlines in a flow around a cylinder. The quiver plot works fine, but the streamlines do not plot at all. I want the streamlines to start at left vertical edge at coordinates x=0 and y=(-40 to +40) mm. Please help, thanks.
I get an error:Error using matlab.internal.math.interp1
Sample points must be unique and sorted in ascending order.
I attach my code and one data file DR1v10vecstat.dat:
close all; clear;
input_folder='D:\ValeckyUT\Valec_tenky_horizontal\';
cd(input_folder);
addpath(genpath(input_folder));
input_file=uigetfile('*.dat');
delimiterIn=' '; headerlinesIn=3;
mydata=importdata(input_file);
I=159; J=99; IJ=[159 99];
x=mydata.data(:,5); x=reshape(x,[I,J]);
y=mydata.data(:,6); y=reshape(y,[I,J]);
U=mydata.data(:,10); Ums = reshape(U,[I,J]);
V=mydata.data(:,11); Vms = reshape(V,[I,J]);
figure(22)
scale=3; quiver(x,y,Ums,Vms,scale); title(['Vector map']); axis equal;
xlabel('x[mm]'); ylabel('y[mm]');
% xs=x(:,1); ys=y(1,:);
[M,N]=size(Ums); [X,Y]=meshgrid(1:N,1:M);
starty=-40:1:40;
startx=zeros(size(starty)); hold on;
% figure(22)
streamline(X,Y,Ums,Vms,startx,starty);

댓글 수: 2

darova
darova 2021년 3월 4일
Did you try to change starting points?
Petr Michalek
Petr Michalek 2021년 3월 4일
I tried to change startx and starty, but I still get odd images like the one below.

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

 채택된 답변

Cris LaPierre
Cris LaPierre 2021년 3월 4일

0 개 추천

I think this is causing your streamlines to not show up
startx=zeros(size(starty))
Based on the example in the documentation, I suggest using ones
startx=ones(size(starty));

댓글 수: 5

Petr Michalek
Petr Michalek 2021년 3월 4일
This helped a bit, but I got this.
Cris LaPierre
Cris LaPierre 2021년 3월 4일
편집: Cris LaPierre 2021년 3월 4일
When I was looking at the linked example, it uses the same x, y, u and v for quiver and streamline, but your code was returning an error. I finally realized you need to transpose your x, y, U and V matrices. This causes the values in each column to correspond to the same x value, and the rows to correspond to the same y value. This is what streamline is expecting.
This code would work with zeros, but below I've modified that line to use the left-most x value instead. Here's my version of your code. I'm using a mat file to load the mydata structure.
load inputFile
I=159; J=99; IJ=[159 99];
x=mydata.data(:,5); x=reshape(x,[I,J])';
y=mydata.data(:,6); y=reshape(y,[I,J])';
U=mydata.data(:,10); Ums = reshape(U,[I,J])';
V=mydata.data(:,11); Vms = reshape(V,[I,J])';
figure
scale=3;
quiver(x,y,Ums,Vms,scale);
title(['Vector map']);
axis equal;
xlabel('x[mm]'); ylabel('y[mm]');
starty=-40:2:40;
% modified startx so that it starts at the left edge
startx=ones(size(starty))*min(x,[],"all");
hold on;
streamline(x,y,Ums,Vms,startx,starty);
hold off
Petr Michalek
Petr Michalek 2021년 3월 5일
That is great, thanks, but I would like to draw also the two vortices behind the cylinder.
Petr Michalek
Petr Michalek 2021년 3월 5일
편집: Petr Michalek 2021년 3월 5일
I managed to draw the two vortices, but I had to draw two sets of streamlines:
starty=-40:1:40; startx1=20*ones(size(starty));
streamline(x,y,Ums,Vms,startx1,starty); hold on;
startx2=ones(size(starty))*min(x,[],"all");
streamline(x,y,Ums,Vms,startx2,starty); hold on;
It is not perfect, but looks quite nice.
Nice. I'll just add that the 2nd set of streamlines does not have to cover the full range of y. You can play around with it to be just what you want it to be.
load dr1v10
scale=3;
quiver(x,y,Ums,Vms,scale);
starty=-40:2:40;
startx=ones(size(starty))*min(x,[],"all");
hold on;
h=streamline(x,y,Ums,Vms,startx,starty);
% add 2nd set of streamlines
streamline(x,y,Ums,Vms,7.5*ones(1,33),-10:0.5:6);
hold off
set(h,'Color','g');

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Vector Fields에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2021년 3월 4일

댓글:

2021년 3월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by