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 CenterFile Exchange에서 Direction of Arrival Estimation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by