Matlab:Streamslice in polar coordinates problem

633 Views Asked by At

I'm struggling with my code, which should create streamlines of vector field in polar coordinates. I have converted (r, phi) components to normal cartesian coordinates (x,y). Components in terms of (r, phi) were distributed uniformly, it means for r = 0:const:10, phi = 0:const:2*pi. Now I'm trying to compute the streamlines of this vector field using streamslice(x,y,wx,wy), but I get an error:

    streamslice(x,y,Gradx,Grady)
Error using griddedInterpolant
Interpolation requires at least two sample points in each
dimension.
Error in interp1 (line 151)
        F = griddedInterpolant(X,V,method);
Error in stream2 (line 62)
    sxi=interp1(xx(:),1:szu(2),sx(k));
Error in streamslice>nicestreams (line 313)
            vertsf = stream2(x,y, u,
            v,xstart,ystart,streamoptions);
Error in streamslice (line 138)
        [vertsout, avertsout] =
        nicestreams(x,y,u,v,density,arrows);

To be detailed, each matrix inside the streamline funtion has dimensions of 201x73. I also tried to compute a little bit different streamslice:

streamslice(x',y',Gradx',Grady')

which sometimes worked for other people (yes, I've done my "research")... but it gives the same error message. I also enclose quiver plot of this vector field if it could help someone. If someone helped mi with this problem I would be really grateful. Really, I don't have any idea. enter image description here

1

There are 1 best solutions below

0
On

From the streamslice documentation:

The arrays X and Y, which define the coordinates for U and V, must be monotonic, but do not need to be uniformly spaced. X and Y must have the same number of elements, as if produced by meshgrid.

Your quiver plot suggests you have defined your vector field on a monotonic grid of r and phi coordinates (although it would help if you specified a minimal example in the question so your problem can be reproduced exactly).

You have two options:

  1. Also calculate the streamslice in polar coordinates and convert the streamlines to cartesian coordinates
  2. Generate a monotonic grid in cartesian space using [x,y] = meshgrid(...), transform these coordinates to polar coordinates to calculate the vector field and convert the field properties back to cartesian components as per the unseen part of your code.