To plot an ellipse

Hi,
I have got the semi axes, with that how to plot an ellipse in matlab. I have tried using the function 'pdeellip', but it didn't work out. Please do help.
Thanks in advance.

 Risposta accettata

Image Analyst
Image Analyst il 12 Mag 2014

1 voto

4 Commenti

Image Analyst
Image Analyst il 12 Mag 2014
Just use the line() function to go from centerX-radiusX to centerX+radiusX at a y value of centerY. Do the same for the vertical axis.
Image Analyst
Image Analyst il 13 Mag 2014
Modificato: Image Analyst il 16 Mag 2020
Priya, you didn't look at the second chunk of code in the FAQ. The first chunk is for an image. If you wanted a plot, you should have used the second code example. Here it is, and I've added the line commands like I suggested to draw the major and minor axes:
xCenter = 12.5;
yCenter = 10;
xRadius = 2.5;
yRadius = 8;
theta = 0 : 0.01 : 2*pi;
x = xRadius * cos(theta) + xCenter;
y = yRadius * sin(theta) + yCenter;
plot(x, y, 'LineWidth', 3);
axis square;
xlim([0 20]);
ylim([0 20]);
grid on;
% Draw lines along the axes
hold on;
line([xCenter, xCenter], [yCenter - yRadius, yCenter + yRadius], ...
'LineWidth', 4, 'Color', [1,0,0]);
line([xCenter - xRadius, xCenter + xRadius], [yCenter, yCenter], ...
'LineWidth', 4, 'Color', [1,0,0]);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
D_coder
D_coder il 16 Mag 2020
Modificato: D_coder il 16 Mag 2020
how would this line plot change for an ellipsoid , I mean 3d?
Use the ellipsoid() function:
[x, y, z] = ellipsoid(0,0,0,5.9,3.25,3.25,30);
figure
surf(x, y, z)
axis equal

Accedi per commentare.

Più risposte (1)

Waqar Khan
Waqar Khan il 18 Mar 2021

0 voti

Hi there, I need help with creating ellipse, I have X = 0.666 and Y=0.87 values, I need to make ellipse from X and Y, kindly guide me. Looking forward to hearing from you.

10 Commenti

Walter Roberson
Walter Roberson il 18 Mar 2021
That is only a single point. There are an infinite number of different ellipses that pass through that point.
Waqar Khan
Waqar Khan il 18 Mar 2021
Actually the X represent the length of major axis and the Y represent the length of minor axis. Can you guide me please with stepwise.
There are still an infinite number of ellipses that can be used, since you have not indicated the center.
xCenter = 0;
yCenter = 0;
xRadius = 2/3;
yRadius = 0.87;
Waqar Khan
Waqar Khan il 18 Mar 2021
Thank you so much for sending the code link, yes because i dont have center values, just the X and Y mentioned. I did try the code you mentiond and i got the plot. Please find the attached.
Now i need to apply gaussain distribution on this, can you guide me about this please. Looking forward to your response.
Walter Roberson
Walter Roberson il 18 Mar 2021
I don't know what it means to apply a Gaussian distribution to a plot.
Waqar Khan
Waqar Khan il 18 Mar 2021
I means i want to apply Gaussain Distribution of sound amplitude on this ellipse. Is it clear now? can you guide me please.
xCenter = 0;
yCenter = 0;
xRadius = 2/3;
yRadius = 0.87;
theta = linspace(0, 2*pi, 100);
%theta(end) = [];
x = xRadius * cos(theta) + xCenter;
y = yRadius * sin(theta) + yCenter;
xvec = linspace(min(x), max(x), 50);
yvec = linspace(min(y), max(y), 50) .';
h = fill(x, y, [0 0 .5], 'FaceAlpha', 0.3); axis equal; xlabel('x'); ylabel('y')
figure
P = 3;
G = 10*exp(-((xvec-xCenter).^2+(yvec-yCenter).^2)./P);
surf(xvec, yvec, G, 'edgecolor', 'none'); view(3); xlabel('x'); ylabel('y'); zlabel('G');
figure
d = sqrt(((xvec-xCenter)./xRadius).^2 + ((yvec-yCenter)./yRadius).^2);
d1 = d <= 1;
surf(xvec, yvec, double(d1), 'edgecolor', 'none'); axis equal; xlabel('x'); ylabel('y'); zlabel('Inside');
figure
G1 = G;
G1(~d1) = nan;
surf(xvec, yvec, G1, 'edgecolor', 'none'); xlabel('x'); ylabel('y'); zlabel('G');
Which is to say that the G matrix here is a gaussian based upon distance from a center, and that G1 is G masked so that everything outside the ellipse is nan. Possibly for your purpose it might make more sense to assign 0 to such places.
Waqar Khan
Waqar Khan il 18 Mar 2021
thank you so much for the code and guidlines let me try it. Much thanks.
Walter Roberson
Walter Roberson il 18 Mar 2021
Note: The P in the equation for G controls how quickly the Gaussian drops off. You should decide more carefully how much you want the gaussian to fall off by the edge of the ellipse.
Also note that what this implements is a circular guassian "clipped" by an ellipse. You could instead make the gaussian itself elliptical, by modifying distance from the center according to the ellipse parameter.
IIt is possible that what you need to do is construct an elliptical gaussian filter, such as for blurring purposes. You would proceed a bit differently in a case like that.
Waqar Khan
Waqar Khan il 18 Mar 2021
Noted, Thank you so much once again, i am reading it carefully.

Accedi per commentare.

Categorie

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by