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.

 채택된 답변

Image Analyst
Image Analyst 2014년 5월 12일

1 개 추천

댓글 수: 4

Image Analyst
Image Analyst 2014년 5월 12일
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 2014년 5월 13일
편집: Image Analyst 2020년 5월 16일
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 2020년 5월 16일
편집: D_coder 2020년 5월 16일
how would this line plot change for an ellipsoid , I mean 3d?
Image Analyst
Image Analyst 2020년 5월 16일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Waqar Khan
Waqar Khan 2021년 3월 18일

0 개 추천

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

Walter Roberson
Walter Roberson 2021년 3월 18일
That is only a single point. There are an infinite number of different ellipses that pass through that point.
Waqar Khan
Waqar Khan 2021년 3월 18일
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 2021년 3월 18일
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 2021년 3월 18일
I don't know what it means to apply a Gaussian distribution to a plot.
Waqar Khan
Waqar Khan 2021년 3월 18일
I means i want to apply Gaussain Distribution of sound amplitude on this ellipse. Is it clear now? can you guide me please.
Walter Roberson
Walter Roberson 2021년 3월 18일
편집: Walter Roberson 2021년 3월 18일
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 2021년 3월 18일
thank you so much for the code and guidlines let me try it. Much thanks.
Walter Roberson
Walter Roberson 2021년 3월 18일
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 2021년 3월 18일
Noted, Thank you so much once again, i am reading it carefully.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

태그

질문:

2014년 5월 12일

댓글:

2021년 3월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by