<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252038</link>
    <title>MATLAB Central Newsreader - How can i plot filled round</title>
    <description>Feed for thread: How can i plot filled round</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 23 May 2009 14:25:15 -0400</pubDate>
      <title>How can i plot filled round</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252038#651872</link>
      <author>Ahmet Mert</author>
      <description>Hi, &lt;br&gt;
&lt;br&gt;
Like this:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://img40.imageshack.us/img40/5587/11156533.png&quot;&gt;http://img40.imageshack.us/img40/5587/11156533.png&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
is that possible?&lt;br&gt;
&lt;br&gt;
thanks</description>
    </item>
    <item>
      <pubDate>Sat, 23 May 2009 17:09:02 -0400</pubDate>
      <title>Re: How can i plot filled round</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252038#651902</link>
      <author>Sadik </author>
      <description>If you mean an ellipse, then you could determine the maximum and minimum x and y values on that ellipse. Let us say, it extends from xmin to xmax and ymin to ymax. Then, you can generate uniformly distributed random numbers in these two ranges and select those that are inside the ellipse.&lt;br&gt;
&lt;br&gt;
[I guess you already know but just to make sure I am clear, let me put it in words. You know that the equation of an ellipse is given by an equals sign. If you change the equals sign with a &quot;smaller than&quot; sign, then any point satisfying this inequality is inside the ellipse.]&lt;br&gt;
&lt;br&gt;
&amp;lt;2002468.10400.1243088746548.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Hi, &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Like this:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://img40.imageshack.us/img40/5587/11156533.png&quot;&gt;http://img40.imageshack.us/img40/5587/11156533.png&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; is that possible?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; thanks</description>
    </item>
    <item>
      <pubDate>Sat, 23 May 2009 17:58:05 -0400</pubDate>
      <title>Re: How can i plot filled round</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252038#651910</link>
      <author>Ahmet Mert</author>
      <description>Could you give me an example?</description>
    </item>
    <item>
      <pubDate>Sat, 23 May 2009 20:03:02 -0400</pubDate>
      <title>Re: How can i plot filled round</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252038#651930</link>
      <author>Sadik </author>
      <description>I had done something similar in the past and fortunately I found the code. At a first glance, it may look complex but in deed it is not. What it does is, it first assumes the major axis is along the x-axis and the minor is along the y-axis [although you can still input values such that major &amp;lt; minor. This is just the naming convention of the code]. It generates points inside this horizontal ellipse [satisfying a smaller-than-or-equal-to inequality] and the number of points is determined by the user. The other inputs are the center (x0,y0) of the ellipse, and the angle it makes with the x-axis [angleOfRotation], as well as the major axis and minor axis lengths. The final input is just to control drawing. If it is 1, the points are plotted with the actual elliptic border surrounding and the two axes. If it is 0, no drawing is performed. In both cases, the output of the function is the set &lt;br&gt;
of generated points. &lt;br&gt;
&lt;br&gt;
An example usage:&lt;br&gt;
&lt;br&gt;
pointsGenerated = generatePointsInsideEllipse(3,2,5,3,pi/4,1000,1);&lt;br&gt;
&lt;br&gt;
A set of points in an ellipse at an angle of pi/4 with the x-axis, centered at (3,2) with axis lengths major = 5, minor = 3. The total number of points to be generated is 1000, but not all of them may fall into the ellipse. Finally, we request a draw.&lt;br&gt;
&lt;br&gt;
The code is as follows. Please copy and paste the entire code to a single blank m-file. [If you have any questions, please feel free to ask me at sadik.hava@gmail.com]&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
% CODE STARTS HERE&lt;br&gt;
function pointsGenerated = generatePointsInsideEllipse(centerX0,centerY0,majorAxis,minorAxis,angleOfRotation,totalNumberOfPoints,drawAlso)&lt;br&gt;
&lt;br&gt;
giveEllipse(centerX0,centerY0,majorAxis,minorAxis,angleOfRotation,drawAlso);&lt;br&gt;
&lt;br&gt;
rotationMatrix = [cos(angleOfRotation) -sin(angleOfRotation);sin(angleOfRotation) cos(angleOfRotation)];&lt;br&gt;
&lt;br&gt;
generatedX = unifrnd(-majorAxis,majorAxis,1,totalNumberOfPoints);&lt;br&gt;
generatedY = unifrnd(-minorAxis,minorAxis,1,totalNumberOfPoints);&lt;br&gt;
&lt;br&gt;
pointsGenerated = zeros(2,totalNumberOfPoints);&lt;br&gt;
&lt;br&gt;
numberInside = 0;&lt;br&gt;
&lt;br&gt;
for n = 1:totalNumberOfPoints&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if zeroMeanEllipseEquation(generatedX(n),generatedY(n),majorAxis,minorAxis) &amp;lt;= 0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;numberInside = numberInside + 1;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pointsGenerated(1,numberInside) = generatedX(n);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pointsGenerated(2,numberInside) = generatedY(n);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
pointsGenerated(:,numberInside+1:end) = [];&lt;br&gt;
&lt;br&gt;
pointsGenerated = rotationMatrix*pointsGenerated+[centerX0*ones(1,length(pointsGenerated));centerY0*ones(1,length(pointsGenerated))];&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
if drawAlso&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;scatter(pointsGenerated(1,:),pointsGenerated(2,:),'.')&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[u,s,v] = svd(cov(pointsGenerated'));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line([centerX0,centerX0+2*sqrt(s(2,2))*u(1,2)],[centerY0,centerY0+2*sqrt(s(2,2))*u(2,2)],'Color','Red','Linewidth',3)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;line([centerX0,centerX0+2*sqrt(s(1,1))*u(1,1)],[centerY0,centerY0+2*sqrt(s(1,1))*u(2,1)],'Color','Red','Linewidth',3)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
function [xPrimeUp,xPrimeDown,yPrimeUp,yPrimeDown] = giveEllipse(centerX0,centerY0,majorAxis,minorAxis,angleOfRotation,drawAlso)&lt;br&gt;
&lt;br&gt;
x = (-majorAxis:0.01:majorAxis)+centerX0;&lt;br&gt;
yUp = minorAxis*sqrt(1 - ((x-centerX0)/majorAxis).^2)+centerY0;&lt;br&gt;
yDown = -minorAxis*sqrt(1 - ((x-centerX0)/majorAxis).^2)+centerY0;&lt;br&gt;
yPrimeUp = (x-centerX0)*sin(angleOfRotation)+(yUp-centerY0)*cos(angleOfRotation)+centerY0;&lt;br&gt;
yPrimeDown = (x-centerX0)*sin(angleOfRotation)+(yDown-centerY0)*cos(angleOfRotation)+centerY0;&lt;br&gt;
xPrimeUp = (x-centerX0)*cos(angleOfRotation)-(yUp-centerY0)*sin(angleOfRotation)+centerX0;&lt;br&gt;
xPrimeDown = (x-centerX0)*cos(angleOfRotation)-(yDown-centerY0)*sin(angleOfRotation)+centerX0;&lt;br&gt;
&lt;br&gt;
if drawAlso&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;figure;plot(xPrimeUp,yPrimeUp)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;hold&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;plot(xPrimeDown,yPrimeDown)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
function result = zeroMeanEllipseEquation(givenX,givenY,majorAxis,minorAxis)&lt;br&gt;
&lt;br&gt;
result = (givenX/majorAxis)^2 + (givenY/minorAxis)^2 - 1;&lt;br&gt;
&lt;br&gt;
% CODE ENDS HERE</description>
    </item>
    <item>
      <pubDate>Sun, 24 May 2009 07:06:18 -0400</pubDate>
      <title>Re: How can i plot filled round</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252038#651975</link>
      <author>Ahmet Mert</author>
      <description>Thanks for he answer. &lt;br&gt;
&lt;br&gt;
I think there was misunderstanding. It's my fault. I didn't explain clearly. But your program will be useful for me. &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
This is what i want:&lt;br&gt;
&lt;br&gt;
plot(rand(100,1),rand(100,1),'o','MarkerFaceColor','k','MarkerEdgeColor','r','MarkerSize',5,'LineWidth',1)&lt;br&gt;
&lt;br&gt;
These points ara similar to this: &lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://img40.imageshack.us/img40/5587/11156533.png&quot;&gt;http://img40.imageshack.us/img40/5587/11156533.png&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
but still there is different. Above link looks more lively, more ...</description>
    </item>
    <item>
      <pubDate>Sun, 24 May 2009 08:23:02 -0400</pubDate>
      <title>Re: How can i plot filled round</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/252038#651979</link>
      <author>Sadik </author>
      <description>The only trick that I can think of is to zoom out by setting the axis limits larger than they are. For instance, in the example you gave with rand, a solution could be setting the limits as follows:&lt;br&gt;
&lt;br&gt;
set(gca,'XLim',[-5 6],'YLim',[-5 6])&lt;br&gt;
&lt;br&gt;
It may still not be optimal...&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;lt;20178373.12520.1243148809452.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; Thanks for he answer. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I think there was misunderstanding. It's my fault. I didn't explain clearly. But your program will be useful for me. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; This is what i want:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; plot(rand(100,1),rand(100,1),'o','MarkerFaceColor','k','MarkerEdgeColor','r','MarkerSize',5,'LineWidth',1)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; These points ara similar to this: &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;a href=&quot;http://img40.imageshack.us/img40/5587/11156533.png&quot;&gt;http://img40.imageshack.us/img40/5587/11156533.png&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; but still there is different. Above link looks more lively, more ...</description>
    </item>
  </channel>
</rss>

