フィルターのクリア

How to plot the five ellipses in the same figure?

1 回表示 (過去 30 日間)
Priya
Priya 2014 年 6 月 19 日
編集済み: Priya 2014 年 8 月 6 日
Here is my code, where when xi_a takes a new value from xi for each iteration, the semi-axes of my ellipse changes.
Now my question is how to plot all the 5 ellipses in the same figure, as it will be easy for me to find by how much they differ from each other.
The two important lines in the coding is made bold ie., xi_a and figure(4)plot

採用された回答

Star Strider
Star Strider 2014 年 6 月 20 日
Hi Priya,
‘. . . plot all the five ellipse generated in 5 iterations in one single figure.’
I don’t see where you get a and b. It must be over the horizon in a part of your code you didn’t post.
The idea in this code snippet here is to create vectors out of a and b as you go through your calculations in a loop, then create a second loop to do the plots.
This is what I would do:
for k1 = 1:5 % LOOP THAT GENERATES ‘a’, ‘b’
% . . . OTHER STATEMENTS IN YOUR CODE . . .
a(k1) = randi(5); % STATEMENT THAT CREATES ‘a’
b(k1) = randi(5); % STATEMENT THAT CREATES ‘b’
% . . . OTHER STATEMENTS IN YOUR CODE . . .
end
%===GENERATE THE ELLIPSE=======
xCenter = 0;
yCenter = 0;
xRadius = a;
yRadius = b;
theta = 0 : 0.01 : 2*pi;
for k1 = 1:length(a)
x = xRadius(k1) .* cos(theta) + xCenter;
y = yRadius(k1) .* sin(theta) + yCenter;
figure(4);
plot(x, y, 'LineWidth', 1)
axis square;
axis equal;
grid on;
xlabel('Longitudinal');ylabel('Lateral');title('Contact ellipse shape')
hold on
end
This plots five ellipses on the same axes using the vector elements of a and b.
  10 件のコメント
Priya
Priya 2014 年 6 月 22 日
Could you please tell me how to give different colours for them ?
Star Strider
Star Strider 2014 年 6 月 24 日
I thought I did. What doesn’t work about that code?

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2014 年 6 月 19 日
Just don't call figure() all those times. In fact, don't call it at all. It will automatically create a figure with one axes, and all plots after you call "hold on" will be added onto the same axes control.
  5 件のコメント
Image Analyst
Image Analyst 2014 年 6 月 20 日
Like xRadius, yCenter, etc.
Priya
Priya 2014 年 6 月 22 日
Thanks for your help as well.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by