Streamline xy(20x1) & velocity component(400x1)

7 views (last 30 days)
Louis
Louis on 29 Oct 2012
Hi I have input the following codes and the same error message seem to keep appearing, which say
'??? Error using ==> stream2 at 47, U,V must all be size 2x2 or greater.'
the following are my codes, please advice where did I make a mistakes? Thanks.
x=xyRp(:,1);
y=xyRp(:,2);
u=VelRp(:,1);
v=VelRp(:,2);
[sx, sy] = meshgrid(linspace(min(x),max(x),400), linspace(min(y),max(y),400));
[x y] = linspace((min(x), max(x), 400), (min(y), max(y), 400))
hhh = stream2(x, y, u, v, sx, sy);

Answers (2)

Walter Roberson
Walter Roberson on 29 Oct 2012
You say your velocity component is 400x1, but you index it as (:,1) and (:,2) which implies that either it is something-by-2 (at least) or else that it is 1 x 400 instead of 400 x 1. If it is 1 x 400 then u and v would come out as single elements. If it is something-by-2 then u and v would come out as column vectors and column vectors are not at least 2 wide to meet the 2 x 2 requirement.
  1 Comment
Louis
Louis on 29 Oct 2012
Actually the velocity component file is Vel(400x2), and i break it into u(400x1) and v(400x1). the same apply to the xy(20x2), which was break into x(20x1) & y(20x1). If that's the case, is it possible to do stream2(x,y,u,v,startx,starty)?

Sign in to comment.


Sean de Wolski
Sean de Wolski on 29 Oct 2012
The error is occuring because x and y are vectors and thus their size is not greate > [2 2]
I don't understand what you're doing with linspace either? Calling it with two output arguments should throw an error.
  2 Comments
Louis
Louis on 29 Oct 2012
Hi, I am not so sure whether do i need to use linspace in this case, as the u and v are both 400x1, but my x and y are only 20x1 each. Can you advise on how I can use these data and plot a stream2. Thank you.
Sean de Wolski
Sean de Wolski on 29 Oct 2012
You need to use meshgrid to generate every pair of xy points:
[xx yy] = meshgrid(xy(:,1),xy(:,2));
Then you need to reshape the u/v vectors to be 20x20 which is the size xx and yy will be. With out knowing how those vectors (u/v) are ordered (and working on the big assumption that this is where the 400 values come from, i.e. each pair of u/v corresponds to one xx/yy pair), it is not possible for me to tell you the correct way to go about reshaping. Perhaps you could shed some light on that. I.e.
is u/v ordered:
x(1)y(1)
x(1)y(2)
or
x(1)y(1)
x(2)y(1)
Or some compltely other way?

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!