Search code examples
matlabmatlab-figure

Ploting constant contours in the same color in matlab


[x,y] = meshgrid(-10:1:10,-10:1:10); 
idx = (x~=0)&(y~=0);     
contour(x(idx)/(x(idx).^2+y(idx).^2).^(3/2),y(idx)/(x(idx).^‌2+y(idx).^2).^(3/2))‌​;

the output is white page!


Solution

  • "delete" the points you do not want:

    [x,y] = meshgrid(-10:0.1:10,-10:0.1:10);
    Idontwantthis = (x.^2+y.^2)<1;
    data= x./(x.^2+y.^2).^(3/2)+y./(x.^2+y.^2).^(3/2);
    data(Idontwantthis)=NaN;
    contourf(data,20);
    

    Note that I replaced / by ./

    I also added more points, as your meshgrid is tiny.

    This is what the result looks like if you use contourf instead of contour (same thing, nicer looking):enter image description here