Creating the X and Y matrices with points of a plot

1 回表示 (過去 30 日間)
Minas Emiris
Minas Emiris 2018 年 4 月 11 日
コメント済み: dpb 2018 年 4 月 11 日
I was wondering how to create two matrices with all the points on an plot, in the case where the values of y are found through a 'for' loop, implying that they are deleted every time the loop continues. For example, I am trying to create two matrices of X and Y summarising all the points of every single arc of angle pi/8 created by the following code:
figure;
theta = pi/8;
hold on
N = 200;
Rmax = 5;
R = linspace (0,Rmax,N);
for i = 1:N
x = linspace(R(i)*cos(theta),R(i),100);
y = sqrt (R(i)^2 - x.*x);
plot(x,y,'b');
end
I realise that if we have two matrices x1 and x2, we can combine them into a single one as X = [x1 ; x2], but I am not sure how to employ this having a 'for' loop. Also, if I manage this, I am afraid that the values of X will not be rearranged to be in ascending order within the matrix, and even if I manage this, then the values of a similar matrix Y (summarising all the values of Y and corresponding to the values of matrix X in appropriate order) will not be accordingly rearranged. Thus, if I attempt then to plot X versus Y, then the values will not give me the original shape.
  1 件のコメント
dpb
dpb 2018 年 4 月 11 日
  1. Preallocate X, Y as N*100 and populate subsections in the loop
  2. Use sortrows or sort with optional second output

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeDirection of Arrival Estimation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by