How to plot streamlines in matlab ???
Show older comments
Hi everybody, I m new. I ve this question like title. I have to plot streamlines with circular cylinder, from PIV data of velocity. For each data I ve one value of X Y U V (2D model), a matrix with n rows x 4 columns. From this matrix, that represents the average values of velocity, I ve just elaborated a quiver plot with the cylinder but I need of your help to understand how can I use streamline function in matlab or if is necessary to write the strem function like fluid mechanics theory. In annex the matrix
Thanks
6 Comments
Bob Thompson
on 25 Feb 2019
So, you already have a series of (x,y) values which compose the different stream lines? Why not just plot them?
ANTONIO LEUZZI
on 25 Feb 2019
Bob Thompson
on 25 Feb 2019
Oh, so your data is velocity (U,V) values at certain (x,y) coordinates, and you want to plot arrows for those velocity vectors?
ANTONIO LEUZZI
on 25 Feb 2019
Bob Thompson
on 25 Feb 2019
How are you identifying which points connect to form a streamline?
ANTONIO LEUZZI
on 25 Feb 2019
Answers (3)
Bob Thompson
on 25 Feb 2019
0 votes
Try using the quiver function. It's not perfect streamlines, but it should give you an idea of what the velocity field looks like, which should essentially achieve the same affect. This should still plot in a 'square' because I suspect that is what is available for your (x,y) data, so that will be the bounds of your 2D plot area. Based on the image you attached you should be getting a grid that is roughly rectangular anyway, as it is a cross section of your flow perpendicular to the cylinder you are flowing around.
data = xlsread('Cartel1.xlsx');
quiver(data(:,1),data(:,2),data(:,3),data(:,4));
ANTONIO LEUZZI
on 26 Feb 2019
0 votes
12 Comments
Bob Thompson
on 26 Feb 2019
No, I am evidently not understanding what you're asking for.
Let's start at the basics to make sure we are on the same page.
You have a set of [x,y,u,v] data that makes up a velocity field.
You want to plot streamlines.
ANTONIO LEUZZI
on 26 Feb 2019
Bob Thompson
on 26 Feb 2019
I'm going to go through this step by step to make sure I am understanding, if I am not, feel free to correct me.
I know that streamline dericìved by stream function and that stream function has got an equation for two both components of velocity (U and V), but my trouble is how to write it in a code.
You have read the documentation and you understand that the streamline function calculates the streamline values for U and V directions using the stream function, but you are not sure how to write a) the stream function in code, b) the streamline command in code?
The streamline function in Matlab actually just generates a line based on the data field that you feed it. I have not looked in greater detail, but I believe this is more a process of generating a series of points with interpolation than it is spceifically using a fluid dynamics stream function.
To respond to problem (a), I do not know the stream function equations off the top of my head, but I also don't know that they are necessary in this situation. If you are looking to write the code to generate streamlines without using the streamline() command then the basic pseudo code I came up with is this:
data = xlsread('Cartel1.xlsx');
ns = 15; % Number of streamlines
streams = zeros(max(data(:,1))*10,2,ns); % Preallocate streamline array size
% (xlocation,ylocation,streamline number)
streams(1,1,:) = 0;
streams(1,2,:) = [min(data(:,2)):(max(data(:,2))-min(data(:,2)))/(ns-1):max(data(:,2))];
c = 1;
for i = 0.1:0.1:max(data(:,1)); % values from x = 0 to max x value
c = c + 1; % Array index counter
streams(c,1,:) = i; % Set new x values
for j = 1:ns; % Loop through each stream y value
streams(c,2,j) = streams(c-1,2,j)+interp2(data(:,1),data(:,2),data(:,4),i,steams(c-1,2,j));
end
end
To respond to problem (b), this is actually quite easy, because you already have the x,y,u,v data necessary to create the streamlines, you just need to decide what the starting points are.
streamline(data(:,1),data(:,2),data(:,3),data(:,4),[zeros(1,100)],[min(data(:,2)):(max(data(:,2))-min(data(:,2)))/99:max(data(:,2))]);
% Should plot 100 streamlines starting on left edge
How can I eventually write the stream function by myself , without streamline of Mat?
See above for beginnings of a code. I do wonder why you feel a need to write this yourself though. Is there a specific problem with the built in streamline command?
Or if I follow the stream2D of Mat hoe is necessary meshgrid of data??
I'm assuming you're getting this idea from the examples found in the streamline documentation. It is not necessary for you to generate a mesh grid because you already have the x,y data in your excel document. The examples shown use meshgrid() because they are generating a generic sample set of data so other poeple can recreate their example.
Because if I meshgrid my data onbtain a square grid
You should be getting a square gird because you are looking at a 2D plot, and those are almost always presented as square grids.
ANTONIO LEUZZI
on 27 Feb 2019
Bob Thompson
on 27 Feb 2019
Double check that ns, and max(data(:,1))*10 are both integers. If they are not, fiddle around with the sizing until they become integers. The code I posted is probably not going to do exactly what you want it to do right off the bat, so you're going to have to do some editting to make it your own.
ANTONIO LEUZZI
on 28 Feb 2019
Bob Thompson
on 28 Feb 2019
Are x and y only increasing? If not sort your data.
data = sortrows(data,[1,2]); % Sort in ascending order with first priority to column 1 and second priority to column 2
Jan
on 4 Mar 2019
@Bob Nbob: When a comment is posted as an answer, you can copy it into the section for commants. Usually this is marked by "[MOVED from section for answers]". You can do this without editor-powers also, but only admins and editors can delete the pseudo-answer afterwards. Here the pseudo-answer got several comments already and moving them is tedious.
ANTONIO LEUZZI
on 7 Mar 2019
ANTONIO LEUZZI
on 7 Mar 2019
Jan
on 7 Mar 2019
@ANTONIO LEUZZI: Uppercase means shouting in an internet forum. With bold type also and a bunch of exclamation marks your message looks excited. Calm down.
Post the current code and a copy of the complete error message.
ANTONIO LEUZZI
on 7 Mar 2019
ANTONIO LEUZZI
on 28 Mar 2019
0 votes
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!